DATEDIFF() function in SQL Server is used to find the difference between the two specified dates.
Features :
- This function is used to find the difference between the two given dates values.
- This function comes under Date Functions.
- This function accepts three parameters namely interval, first value of date, and second value of date.
- This function can include time in the interval section and also in the date value section.
Syntax :
DATEDIFF(interval, date1, date2)
Parameter :
This method accepts three parameters as given below :
- interval : It is the specified part which is to be returned. Moreover, the values of the interval can be as given below:
- year, yyyy, yy = Year, which is the specified year.
- quarter, qq, q = Quarter, which is the specified quarter.
- month, mm, m = month, which is the specified month.
- dayofyear, dy, y = Day of the year, which is the specified day of the year.
- day, dd, d = Day, which is the specified day.
- week, ww, wk = Week, which is the specified week.
- weekday, dw, w = Weekday, which is the specified week day.
- hour, hh = hour, which is the specified hour.
- minute, mi, n = Minute, which is the specified minute.
- second, ss, s = Second, which is the specified second.
- millisecond, ms = Millisecond, which is the specified millisecond.
- date1, date2 : The two specified dates in order to find the difference between them.
Returns :
It returns the difference between the two specified dates.