DATEDIFF (Transact‑SQL)

Synopsis

DATEDIFF ( datepart , startdate , enddate )

Returns the count (as a signed integer) of the specified datepart boundaries crossed between the startdate and enddate.

Parameters

ParameterDescription
datepartThe part of the date to calculate the difference for. See DATEPART for a full list.
startdateA date expression that serves as the start of the interval.
enddateA date expression that serves as the end of the interval.

Return Type

Returns int. The signed integer result can be positive, zero, or negative.

Remarks

The result is calculated based on the number of datepart boundaries crossed. The sign of the result indicates the direction (negative when startdate is later than enddate).

View Example →

When datepart is year, quarter, month, dayofyear, or day, the result reflects the count of those boundaries crossed, not the absolute calendar difference between the two dates.

Related Topics