jbenson001,
Your explanation is not quite right. First of all, SQL Server stores datetime as a pair of integers.
However, it often helps to think of DateTime's as floating point numbers. The whole number part would represent the numbers of days that have elapsed since Jan 1, 1900, and the fraction part would represent the time (0.25 = 8 AM, 0.5 = Noon, 0.75 = 8 PM).
For example:
Code:
Select Convert(Float, GetDate()), GetDate()
If we convert GetDate() to float, we can see the whole number and the fraction part. Another way to remove the time component is to convert to float, take the Floor, and convert back to datetime. Like this:
Code:
Select Convert(DateTime, Floor(Convert(Float, GetDate())))
This method performs almost as well as the DateAdd/DateDiff method. In fact, you have to try pretty hard to notice a difference.
The real key to this method is how DateDiff works. DateDiff returns an integer representing the number of TRANSITIONS based on the interval (the first parameter). For example, The difference between 11:59:59 PM and 12:00:01 AM is 2 minutes, but DateDiff(day will report 1 day because the transition occurs exactly at midnight.
So... DateDiff returns an INTEGER number of days that have elapsed since Jan 1, 1900. We then add this number of days to Jan 1, 1900. Since we already have an integer from the DateDiff, the DateAdd will add an integer number of days to a date without time. In this case, the date without time is the 0 (which represents Jan 1, 1900 00:00:00).
-
George
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom