Application
This function is used to find the difference between two specified values of date.
- Date Interval Calculation: The number of specified date parts between two provided dates is found using the DATEDIFF() method.
- Date Part Flexibility: Years, months, days, hours, minutes, and seconds are among the date parts that are supported.
- Versatility in Date Comparisons: DATEDIFF() makes it possible to compare dates from several time periods or frames, which makes trend analysis easier.
- Simple Syntax and Implementation: The syntax of the function in SQL Server queries is simple to understand and apply.
DATEDIFF() Function in SQL Server
DATEDIFF() function in SQL Server is used to find the difference between the two specified dates or times.
Features
- This function is used to find the difference between the two given date values.
- This function comes under Date Functions.
- This function can include time in the interval section and also in the date value section.
Syntax
DATEDIFF(datepart, Start_date, End_date);
Parameter
This method accepts three parameters as given below:
- datepart: It is the specified part that is to be returned. Moreover, the values of the interval can be given below.
datepart |
abbreviations |
---|---|
year |
yyyy,yy,y |
quarter |
qq,q |
dayofyear |
dy |
day |
dd,d |
week |
ww,wk |
weekday |
dw,w |
hour |
hh |
minute |
mi,n |
second |
ss,s |
millisecond |
ms |
- Start_date: The starting date of the interval.
- End_date: The ending date of the interval.
Return Type of DATEDIFF() is: int
Return Value: It returns the difference between the two specified dates.