Understanding the usage of the MONTHS_BETWEEN function
As the function’s name indicates, the MONTHS_BETWEEN
function returns the number of months between two defined dates. The syntax of the MONTHS_BETWEEN
function is stated in the following block:
MONTHS_BETWEEN(date_val1, date_val2)
Let’s look at the results. To get a positive value, the first parameter value (date_val1
) must be greater than the second parameter (date_val2
). If not, a negative result will be provided:
select MONTHS_BETWEEN(TO_DATE ('15.12.2022', 'DD.MM.YYYY'), TO_DATE ('15.2.2022', 'DD.MM.YYYY')) from dual; --> 10 select MONTHS_BETWEEN(TO_DATE ('15.2.2022', 'DD.MM.YYYY'), ...