datediff

Returns the duration of time between two date or time values.

Function

result = datediff(period, first, second)

Arguments

ArgumentData Type
perioddatepart
firstdate or time or datetime
seconddate or time or datetime
resultinteger

Comments

Counts the number of period intervals from first to second. Returns a positive number if the second value is chronologically after the first value, and a negative value if it is before.

This function operates in the local time-zone if datetime inputs are provided. See Dates, Times and Time Zones.

Take care when calculating time differences that span across a daylight saving adjustment. The datediff result is calculated based on the actual time that has elapsed, therefore a day is not necessarily equal to 24 hours.

Examples

result = datediff(year, #2000-12-31#, getdate()) /* result is 19 if the current year is 2019 */
result = datediff(day, #2019-06-20#, #2019-07-10#) /* result is 20 */
result = datediff(day, #2019-07-10#, #2019-06-20#) /* result is -20 */