MONTHS_BETWEEN function in Oracle

MONTHS_BETWEEN is one of the vital Date/Time functions of Oracle. It is used to get the number of months between two mentioned dates. The MONTHS_BETWEEN function is supported in the various versions of the Oracle/PLSQL, including, Oracle 12c, Oracle 11g, Oracle 10g, Oracle 9i and Oracle 8i.

Syntax:

MONTHS_BETWEEN ( date1, date2 )

Parameters: date1: It is used to specify the first date. date2: It is used to specify the second date.

Example 1:

MONTHS_BETWEEN (TO_DATE ('2019/01/01', 'yyyy/mm/dd'), TO_DATE ('2019/03/14', 'yyyy/mm/dd') )

Output:

 -2.41935483870968

Explanation: The result will be the difference of the two dates.

Example 2:

MONTHS_BETWEEN (TO_DATE ('2019/10/01', 'yyyy/mm/dd'), TO_DATE ('2019/06/14', 'yyyy/mm/dd') )

Output:

3.58064516129032

Explanation: The result will be the difference of the two dates.

Please follow and like us:
Content Protection by DMCA.com