Categories: Date/Time
MONTHS_BETWEEN
Returns the number of months between two date or timestamp values.
Syntax
MONTHS_BETWEEN(date_timestamp_expression1 string, date_timestamp_expression2 string) → float
- date_timestamp_expression1: The
DATE
orTIMESTAMP
to subtract from. - date_timestamp_expression2: The
DATE
orTIMESTAMP
to subtract.
Examples
MONTHS_BETWEEN exampleSELECT MONTHS_BETWEEN('2018-11-01 10:30:00', '2019-02-28')
-- -3.870967741935484
Usage Notes
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.