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.

  • second_date (Operand) – The ending date or array of dates.

Return type:

Formula

Returns:

The number of months between the two dates. If input arrays have unequal lengths the returned formula will evaluate to an error.

Raises:

ValueError – If either input is not a date or datetime type.

Examples

MONTHSBETWEEN(DATE(2025, 1, 1), DATE(2025, 3, 10))
# Returns 2

``first_date`` — accepted types

  • DATE

  • DATETIME

  • DATETIME_ARRAY

  • DATE_ARRAY

``second_date`` — accepted types

  • DATE

  • DATETIME

  • DATETIME_ARRAY

  • DATE_ARRAY

Return types

  • INTEGER

  • INTEGER_ARRAY