Why am I using the DATEADD and DATEDIFF functions here?
They are used to remove time information! I want to be sure that only date information is used. So I set the time to
00:00:00.000 the fastest way I know.[ie: DATEADD(day, DATEDIFF(day, 0, getdate()), 0) ]
I've not seen this method used before. Although it pops up from time-to-time on this site, the "best" method I knew for stripping the time was:
cast(floor(cast(getdate() as float)) as datetime)
After some testing (with a rather clunky while loop) I got the following table:
iterations | datediff | floor |
1 | 0 | 0 |
10 | 0 | 0 |
100 | 0 | 0 |
1000 | 7 | 6 |
10000 | 68 | 75 |
100000 | 712 | 810 |
Iterations is the number of times the method was used, run 100 times each, and then an average taken. Seems to be that if you're performing a low number of "time strips" there is negligible difference. Indeed, for 100,000 iterations there is only a 98 millisecond gain. Less than 1 second.
So, *is* there a real difference of one method over the other?
S.