Working with SQL Server Date/Time Variables: Part Four - Date
Math and Universal Time - Page 2 June 3, 2003 The DATEDIFF
function is used to calculate the number of date and time
boundaries crossed between two different dates. This function
returns an integer value. A call to the DATEDIFF function takes
the following format: DATEDIFF(datepart, startdate, enddate)
Where datepart is one of the following: year, quarter, month,
dayofyear, day, hour, minute, second or millisecond. Startdate
and enddate are datetime values for which you want to find the
difference. As stated above, the DATEDIFF function is used to
calculate the number of date and time boundaries crossed between
two dates. So what value do you think might be returned if you
used '12/31/2002 23:59:59.997' for the startdate and '01/01/2003
00:00:00.000' for the enddate, when the datepart is day or year?
Clearly, the amount of time between these two dates is only 3
milliseconds. Find out by running the following two SELECT
statements. What did you disc