Month and Year Difference in oracle.

  • Think I have Date as SysDate Minus 20101101.

    I should Trunc SysDate & Given date to YYYYMM Now I shoud do minus given date.

    EX:- 201409-201011

    It should only calculate Months not Days.

    I tried Month_Between but is giving wrong answer.

    Please help.

  • Why is it giving a wrong answer? In other words, what would be the correct answer and what are you getting right now?

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • this is an example. I have a similar situation. When i use the Month Difference it also taking the Dates in to considerations os the results are comming as decimals.

    This willnot kill server. it just the claims calculation.

  • The following code returns a value of 10. Is that what you're after?

    SELECT months_between(TRUNC(TO_DATE( '20131101', 'YYYYMMDD'), 'MM'), TRUNC(SYSDATE, 'MM'))

    FROM Dual;

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • Thanks Luis. now only Months are calculatiing.

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply