MONTHS_BETWEEN function

MONTHS_BETWEEN(x,y) returns the number of months between x and y. If x is before y on the calendar, the number returned is positive; otherwise the number is negative.


SQL> SELECT MONTHS_BETWEEN('25-MAY-2009', '15-JAN-2012') FROM dual;

MONTHS_BETWEEN('25-MAY-2009','15-JAN-2012')
-------------------------------------------
                                 -31.677419

SQL>

The next example reverses the same dates and the returned result is a negative number of months:


SQL> SELECT MONTHS_BETWEEN('15-JAN-2012', '25-MAY-2009')FROM dual;

MONTHS_BETWEEN('15-JAN-2012','25-MAY-2009')
-------------------------------------------
                                 31.6774194

SQL>
Home »
Oracle »
Date functions » 

Related: