DATEDIFF Function

Returns the number of calendar or clock boundaries crossed between two dates. A calendar boundary is a transition from one day to the next, from one month to the next, etc. A clock boundary is a transition from one hour of the day to the next, one minute of the day to the next, etc.

Syntax

DATEDIFF(date-part, start-date, end-date)

Parameters

Return Value

An integer representing the number of the specified date-part boundaries that are crossed between start-date and end-date.

Example

-- Prints "1" because the clock crosses midnight once.
PRINT DATEDIFF('day', '2016-03-04 03:53', '2016-03-05 11:53');

-- Prints "1" because the clock crosses the top of the hour once.
PRINT DATEDIFF('hh', '2016-01-01 03:59', '2016-01-01 04:01');

-- Prints "0" because the clock does not cross the top of the hour.
PRINT DATEDIFF('hh', '2016-01-01 03:50', '2016-01-01 03:52');