description |
---|
Returns the number of months between two date or timestamp values. |
- date_timestamp_expression1: The
DATE
orTIMESTAMP
to subtract from. - date_timestamp_expression2: The
DATE
orTIMESTAMP
to subtract.
Examples
{% code title="MONTHS_BETWEEN example" %}
SELECT MONTHS_BETWEEN('2018-11-01 10:30:00', '2019-02-28')
-- -3.870967741935484
{% endcode %}
If date or timestamp date_timestamp_expression1
represents an earlier point in time than date_timestamp_expression2
, then MONTHS_BETWEEN(date_timestamp_expression1, date_timestamp_expression2)
returns a negative value; otherwise it returns a positive value. You can use a date value for one input parameter and a timestamp for the other.