RSS Feed

DATEDIFF()

DATEDIFF()

Returns the difference between the two dates.

Syntax

DATEDIFF (datepart ,startdate ,enddate)

datepartAbbreviations
yearyy, yyyy
quarterqq, q
monthmm, m
dayofyeardy, y
daydd, d
weekwk, ww
weekdaydw
hourhh
minutemi, n
secondss, s
millisecondms

Example 1 of DATEDIFF()

GetDate() shows todays date.

SELECT DATEDIFF(day,GetDate()-1,GetDate())

1

Example 2 of DATEDIFF()


SELECT DATEDIFF(hh,GetDate()-1,GetDate())

24

Example 3 of DATEDIFF()

SELECT DATEDIFF(mi,GetDate()-1,GetDate())

1440