MONTHS_BETWEEN

The MONTHS_BETWEEN function returns an estimate of the number of months between expression1 and expression2.

Read syntax diagramSkip visual syntax diagram
>>-MONTHS_BETWEEN--(--expression1--,--expression2--)-----------><

expression1
An expression that returns a value of one of the following built-in data types: a date, a timestamp, a character-string, or a graphic-string.
If expression1 is a character or graphic string, it must not be a CLOB or DBCLOB and its values must be a valid string representation of a date or timestamp. For the valid formats of string representations of dates and timestamps, see String representations of datetime values
expression2
An expression that returns a value of one of the following built-in data types: a date, a timestamp, a character-string, or a graphic-string.
If expression2 is a character or graphic string, it must not be a CLOB or DBCLOB and its values must be a valid string representation of a date or timestamp. For the valid formats of string representations of dates and timestamps, see String representations of datetime values
If expression1 represents a date that is later than expression2, then the result is positive. If expression2 represents a date that is later than expression1, then the result is negative.Start of change
  • If expression1 and expression2 represent dates with the same day of the month or the last day of the month, or both arguments represent the last day of their respective months, the result is a the whole number difference based on the year and month values ignoring any time portions of timestamp arguments.
  • Otherwise, the whole number part of the result is the difference based on the year and month values. The fractional part of the result is calculated from the remainder based on an assumption that every month has 31 days. If either argument represents a timestamp, the arguments are effectively processed as timestamps with maximum precision, and the time portions of these values are also considered when determining the result.
End of change

The result of the function is a DECIMAL(31,15). If either argument can be null, the result can be null; if either argument is null, the result is the null value.

Examples