And now because of DATE there's a simpler way to do the conversion: CAST(@dt as DATE). But is this any faster?
The short answer is no, but it doesn't seem to be any slower either. I ran a quick test:
declare @dtest datetime declare @i int = 0, @j int = 0 declare @start datetime set @start = GETDATE() while @i < 1000000 begin set @dtest = DATEADD(dd, 0, DATEDIFF(dd, 0, GETDATE())) set @i = @i + 1 end print datediff(ms, @start, getdate()) set @start = GETDATE() while @j < 1000000 begin set @dtest = CAST(GETDATE() as DATE) set @j = @j + 1 end print datediff(ms, @start, getdate())
In half a dozen runs, the two versions never varied by more than a handful of ms. Feel free to try on your own and let me know if you see anything different.
No comments:
Post a Comment