This Oracle tutorial explains how to use the Oracle/PLSQL MONTHS_BETWEEN function with syntax and examples.
The Oracle/PLSQL MONTHS_BETWEEN function returns the number of months between date1 and date2.
The syntax for the MONTHS_BETWEEN function in Oracle/PLSQL is:
MONTHS_BETWEEN( date1, date2 )
The first date used to calculate the number of months between.
The second date used to calculate the number of months between.
The MONTHS_BETWEEN function returns a numeric value.
The MONTHS_BETWEEN function can be used in the following versions of Oracle/PLSQL:
Let's look at some Oracle MONTHS_BETWEEN function examples and explore how to use the MONTHS_BETWEEN function in Oracle/PLSQL.
For example:
MONTHS_BETWEEN (TO_DATE ('2003/01/01', 'yyyy/mm/dd'), TO_DATE ('2003/03/14', 'yyyy/mm/dd') )
would return -2.41935483870968
Another example using the MONTHS_BETWEEN function in Oracle/PLSQL is:
MONTHS_BETWEEN (TO_DATE ('2003/07/01', 'yyyy/mm/dd'), TO_DATE ('2003/03/14', 'yyyy/mm/dd') )
would return 3.58064516129032
Another example using the MONTHS_BETWEEN function is:
MONTHS_BETWEEN (TO_DATE ('2003/07/02', 'yyyy/mm/dd'), TO_DATE ('2003/07/02', 'yyyy/mm/dd') )
would return 0
A final example using the MONTHS_BETWEEN function in Oracle/PLSQL is:
MONTHS_BETWEEN (TO_DATE ('2003/08/02', 'yyyy/mm/dd'), TO_DATE ('2003/06/02', 'yyyy/mm/dd') )
would return 2