How Can We Help?
Introduction:
In this tutorial, we are going to explain how to use Oracle MONTHS_BETWEEN function with basic syntax and many examples for better understanding.
MONTHS_BETWEEN returns the number of months between two dates.
Syntax:
MONTHS_BETWEEN( first_date, second_date )
Name | Description |
first_date | The first date argument of the function. |
second_date | The second date argument of the function. |
Applies to::
Oracle 19c, Oracle 18c, Oracle 12c, Oracle 11g, Oracle 10g, Oracle 9i, Oracle 8i
Examples:
Let’s take some examples about Oracle MONTHS_BETWEEN and how to use it:
SELECT MONTHS_BETWEEN (TO_DATE ('01-05-2020', 'DD-MM-YYYY'), TO_DATE ('01-01-2020', 'DD-MM-YYYY')) "# Of Months"
FROM DUAL;
SELECT MONTHS_BETWEEN (TO_DATE ('15-05-2019', 'DD-MM-YYYY'), TO_DATE ('15-03-2020', 'DD-MM-YYYY')) "# Of Months"
FROM DUAL;
SELECT MONTHS_BETWEEN (TO_DATE ('15-05-2019', 'DD-MM-YYYY'), TO_DATE ('15-05-2019', 'DD-MM-YYYY')) "# Of Months"
FROM DUAL;
SELECT MONTHS_BETWEEN (TO_DATE ('15-05-2020', 'DD-MM-YYYY'), TO_DATE ('19-02-2020', 'DD-MM-YYYY')) "# Of Months"
FROM DUAL;
Similar functions to Oracle MONTHS_BETWEEN:
NEXT_DAY : returns the date of the next weekday specified.
ADD_MONTHS : Add number of months to a date
In this tutorial, you have learned how to use the Oracle MONTHS_BETWEEN function to calculate the number of months between two dates.
Hopefully, it was clear and concise.