MONTHS_BETWEEN
Purpose
This function returns the number of months between two date values.
Syntax
months_between::=
Usage Notes
- If a timestamp is entered, only the date contained therein is applied for the computation.
- If the days are identical or both are the last day of a month, the result is an integer.
- If the first date value is earlier than the second date value, the result is negative.
- For data type
TIMESTAMP WITH LOCAL TIME ZONE
this function is calculated within the session time zone.
Example
SELECT MONTHS_BETWEEN(DATE '2000-01-01', DATE '1999-12-15') MB1,
MONTHS_BETWEEN(TIMESTAMP '2000-01-01 12:00:00',
TIMESTAMP '1999-06-01 00:00:00') MB2;
Result
MB1 | MB2 |
0.548387096774194 | 7 |