Find how many months between dates

nate100

Member
I like to find out how many months there are between 2 given dates.
For example:
01/01/2010 - 02/28/2010 will result in 2 months.

If you have:
01/01/2010 - 03/02/10 the result would be 2 months and 2 days.

Any idea on how to handle this.

Thanks in advance.
 
INTERVAL function

Returns the time interval between two DATE, DATETIME, or DATETIME-TZ values as an INT64 value.

Syntax

INTERVAL (datetime1, datetime2, interval-unit)

datetime1 An expression whose value is a DATE, DATETIME, or DATETIME-TZ.

datetime2 An expression whose value is a DATE, DATETIME, or DATETIME-TZ.

interval-unit A character constant, or a character expression that evaluates to one of the following time units: ‘years’, ‘months’, ‘weeks’, ‘days’, 'hours’, ‘minutes’, ‘seconds’ or ‘milliseconds’. These values are case insensitive and may be singular.

Notes

This function returns a signed integer value (positive or negative). For example, if datetime1 is less than datetime2, the INTERVAL function returns a negative value.

If datetime1 or datetime2 is a DATE or DATETIME, the time value defaults to midnight and the time zone value defaults to the session's time zone, respectively.

You are responsible for managing value overflow, if any.
 
Back
Top