Skip to content

Latest commit

 

History

History
25 lines (17 loc) · 1.15 KB

months_between.md

File metadata and controls

25 lines (17 loc) · 1.15 KB
description
Returns the number of months between two date or timestamp values.

MONTHS_BETWEEN

Syntax

MONTHS_BETWEEN(date_timestamp_expression1 string, date_timestamp_expression2 string) → float

  • date_timestamp_expression1: The DATE or TIMESTAMP to subtract from.
  • date_timestamp_expression2: The DATE or TIMESTAMP to subtract.

Examples

{% code title="MONTHS_BETWEEN example" %}

SELECT MONTHS_BETWEEN('2018-11-01 10:30:00', '2019-02-28')
-- -3.870967741935484

{% endcode %}

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.