DATEDIFF (datepart, start, end)
Returns an integer for the difference between the two dates. The integer is the number of date and time boundaries crossed between the two dates.
For example, suppose that table mytest has two columns,col1 and col2, both of which are DATETIME. The value in col1 is 2000-01-01 11:11:11.234 and the value in col2 is 2004-09-11 10:10:10.211. The following SELECT statement returns 56, because that is the difference in months between col1 and col2: SELECT DATEDIFF(month, col1, col2) as Month_Difference FROM mytest.
Datepart specifies the part of the date on which to calculate the difference and must be one of the following values.
Start specifies the beginning date for the difference calculation. Start is an expression that returns a DATETIME value or a Unicode character string in a DATE format.
End specifies the ending date for the difference calculation. End is an expression that returns a DATETIME value or a Unicode character string in a DATE format.
Start is subtracted from end. An error is returned if the return value is outside of the range for integer values.