Skip to content

MONTHS_BETWEEN

  • date1: The first parameter referring to the later date in the sequence of the two dates that are being compared.
  • date2: The second parameter referring to the earlier date which will be compared with the first date to calculate the number of months between them.
SELECT MONTHS_BETWEEN(TO_DATE('2020-12-31', 'YYYY-MM-DD'),
TO_DATE('2020-01-01', 'YYYY-MM-DD')) AS months_diff
FROM dual;
MONTHS_DIFF
----------------
12

The MONTHS_BETWEEN function in Oracle calculates the number of months between two dates. In the provided example, it calculates the number of months between ‘2020-12-31’ and ‘2020-01-01’. The result is 12, indicating that the two dates are 12 months apart.