Introduction
SQL is one of the most commonly used languages in Database Management Systems for making queries on data. The Date datatype is one of the most essential Datatypes in SQL. SQL Server provides plenty of date and time methods to manipulate data in the form of date and time. One such method is the DATEDIFF() function.

This blog will discuss the DATEDIFF() function in detail. We will discuss the syntax, parameters, and return type of the DATEDIFF() function. We will also look at examples of the DATEDIFF() function and its code implementations. In the end, we will conclude by discussing some frequently asked questions.
Syntax, Parameter & Return Type of the DATEDIFF() Function
This section will discuss the syntax, parameters, and return type of the DATEDIFF() function in detail.
DATEDIFF (interval, date1, date2)
The syntax of the DATEDIFF() function is simple. It takes three parameters, the interval, and two dates, to calculate the difference between them. All of these parameters are required.
Parameters
The DATEDIFF() function takes three parameters:
-
Interval - It is the time interval in which the date is to be returned.
-
Date1- This is the starting date from which the difference is to be calculated.
-
Date2- This is the final date until which the difference is to be calculated.
All parameter values and their notations are described with the help of a table below.
Parameter |
Description / Notation |
---|---|
Interval |
Year - year, yyyy, yy
Quarter - quarter, qq, q
Month - month, mm, m
Day - day, dd, d
Day of the year - dayofyear, dy, y
Week - week, ww, wk
Weekday - weekday, dw, w
Minute - minute, mi, m
Second - second, ss, s
Hour - hour, hh
Millisecond - millisecond, ms |
Date1 | This is the starting date from which the difference is to be calculated. |
Date2 | This is the final date until which the difference is to be calculated. |
Return Type
After calculating the difference between the dates, the DATEDIFF() function returns the difference between the dates in the format specified by the interval parameter.
Also see, SQL EXCEPT