The DATEDIFF function is used in Microsoft SQL Server to return the time between two dates/date columns.
In this example, we want to find out how many days an employee has been working for the organizaiton since their hire date.
DATEPART Reference Table
DATEDIFF(datepart, startDate, endDate)|
Results (Query ran on 12/13/2011)
SELECT employeeName as [Employee Name],
DATEDIFF(day,hiredate,GETDATE()) as [Total Days Since Hire]|
|Employee Name||Total Days Since Hire|
The SQL DATEDIFF function can be very useful when you are interested in finding out how much time there is between two dates, a date and a date field, or two date fields.
Recommended Books & Training Resources