Date Rounding Tactics and the Tiny Devil of SMALLDATETIME

With every new year I think a little bit about time and dates. This posts looks a little more at that in TSQL. Rounding Dates: Which way is best? Sometimes in TSQL you need to round a datetime value to the precision of either a day, hour, minute, or second. I realized recently that I have a few ways I know how to do this, but I wasn’t sure which was the most efficient. I did a little searching and didn’t find anything super conclusive. I had a little chat with Jeremiah Peschka (blog | twitter) and he told me which way he thought was fastest and why. And so I decided to run some tests. Jeremiah has a way of being right about these things, but I had to see for myself. I’ll go ahead and tell you: He was totally right, and I’ll show you why. But I…
Read More