The Oracle/PLSQL date function MONTHS_BETWEEN returns the number of months between two dates that are passed as arguments.
Syntax:
MONTHS_BETWEEN(date1, date2) Example code: <pre lang="plsql">SELECT TRUNC(SYSDATE), MONTHS_BETWEEN(SYSDATE, '31-JUL-2009') FROM dual
trunc(sysdate) months_between
———————————–
12/31/2009 5
SELECT TRUNC(SYSDATE), MONTHS_BETWEEN(SYSDATE, '11-FEB-2009') FROM dual
trunc(sysdate) months_between
——————————————–
12/31/2009 10.6481179062127
This return fraction of month. trunc can be used to get the whole number as shown in the following code
SELECT trunk(SYSDATE), TRUNC(MONTHS_BETWEEN(SYSDATE, '11-FEB-2009')) FROM dual
trunc(sysdate) months_between
——————————————-
12/31/2009 10