MONTHS_BETWEEN

functionsupportedCore SQL functions

docs.snowflake.com ↗

Date & time functions

Returns the number of months between two DATE or TIMESTAMP values. For example, MONTHS_BETWEEN('2020-02-01'::DATE, '2020-01-01'::DATE) returns 1.0.

Syntax

MONTHS_BETWEEN( <date_expr1> , <date_expr2> )

Parameters

NameRequiredDescription
date_expr1requiredThe date to subtract from.
date_expr2requiredThe date to subtract.

Returns

A FLOAT representing the number of months between the two dates. The number is calculated as described below: - The integer portion of the FLOAT is calculated using the year and month parts of the input values. - In most situations, the fractional portion is calculated using the day and time parts of the input values. (When calculating the fraction of a month, the function considers each month to be 31 days long.) However, there are two exceptions: If the days of the month are the same (e.g. February 28 and March 28), the fractional portion is zero, even if one or both input values are timestamps and the times differ. - If the days of the month are both the last day of the month (e.g. February 28 and March 31), the fractional portion is zero, even if the days of the month are not the same. For example, the function considers each of the following pairs of dates/timestamps to be exactly 1.0 months apart:

Usage notes

See also