date_diff(datepart, startdate, enddate)
Returns an integer representing the interval that has elapsed between two dates.
| |
|---|
datepart | The part of the date to use when calculating the difference. Allowed values are:yearmonthquarterdayweekhourminutesecond
|
startdate | The start date of the interval. |
enddate | The end date of the interval. |
The difference between two dates is calculated based on the difference in the indicated date parts. For example, the year difference between two dates is calculated by subtracting the year part of startdate from the year part of enddate.
Suppose OrderDate and ShipDate are DateOnly types. The order date is 31-1-2017 and the ship date is 1-2-2018.
The year difference between the order date and ship date is 1.
1date_diff("year", 'OrderDate' 'ShipDate');
The month difference between the order date and ship date is 2.
1date_diff("month", 'OrderDate' 'ShipDate');
If startdate is after enddate, the result is a negative integer.
See Also