Purpose
You can call this function to return the number of months between date1 and date2.
Syntax
MONTHS_BETWEEN (date1, date2)
Parameters
| Parameter | Description |
|---|---|
| date1 | A value of the DATE data type. |
| date2 | A value of the DATE data type. |
Return type
The return type is NUMBER.
If
date1is later thandate2, the function returns a positive number.If
date1is earlier thandate2, the function returns a negative number.
Examples
The following example returns the number of months between 2030-11-17 and 2022-01-15.
obclient> SELECT MONTHS_BETWEEN(TO_DATE('2030-11-17','YYYY-MM-DD'),TO_DATE('2022-01-15','YYYY-MM-DD')) "MONTHS" FROM DUAL;
+------------------------------------------+
MONTHS
+------------------------------------------+
106.064516129032258064516129032258064516
+------------------------------------------+
1 row in set