- DATE
- TIMESTAMP
- TIMESTAMP WITH TIME ZONE
The two argument to MONTHS_BETWEEN can be one of the preceding data types, but the two arguments must be the same data type. For example, you cannot pass a DATE as the first parameter and a TIMESTAMP as the second parameter.
Since TIMESTAMP values are stored in UTC time within the database and lack a time zone, the session time zone is used to interpret the time stamp value within the function. For TIMESTAMP WITH TIME ZONE values, the time zone component is used to interpret the time stamp value within the function.
- Later than date_timestamp_value1, the result is negative.
- Earlier than date_timestamp_value1, the result is positive.
If date_timestamp_value1 and date_timestamp_value2 are either the same days of the month or both last days of months, the result is always an integer. Otherwise, MONTHS_BETWEEN calculates the fractional portion of the result based on a 31-day month and considers the difference in time components of date_timestamp_value1 and date_timestamp_value2. The Gregorian calendar is supported.
Timestamps without a time zone are compared in the local time zone. This matters solely for the purpose of determining if two timestamps reside on the same day or are both the last day of a month. Timestamps with a time zone are converted to UTC before being compared in order to ensure the times are in the same zone.