MONTHSBETWEEN
- MONTHSBETWEEN(first_date, second_date)[source]
Returns the number of months between two dates.
The MONTHSBETWEEN function calculates the difference in months between first_date and second_date. The result is positive if second_date occurs after first_date and negative if it occurs before. This function supports both single dates and arrays of dates.
- Parameters:
first_date (
Operand) –The starting date or array of dates.
Supported types:
DATE
DATETIME
DATE_ARRAY
DATETIME_ARRAY
second_date (
Operand) –The ending date or array of dates.
Supported types:
DATE
DATETIME
DATE_ARRAY
DATETIME_ARRAY
- Return type:
- Returns:
The number of months between the two dates. If input arrays have unequal lengths the returned formula will evaluate to an error.
Supported types:
INTEGER
INTEGER_ARRAY
- Raises:
ValueError – If either input is not a date or datetime type.
Examples
MONTHSBETWEEN(DATE(2025, 1, 1), DATE(2025, 3, 10)) # Returns 2