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 organization since their hire date.
DATEDIFF(datepart, startDate, endDate)
DATEPART Reference Table
SELECT employeeName as [Employee Name], DATEDIFF(day,hiredate,GETDATE()) as [Total Days Since Hire] FROM employees
Results (Query ran on 12/13/2011)
|Employee Name||Total Days Since Hire|
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.