Best approach to remove time part of datetime in SQL Server -
Which method provides the best performance when extracting time from a datetime field in SQL Server?
a) Select DATEADD (DD, DATEDIFF (dd, 0, getdate ()), 0)
or
b) Select cast (
The second method sends some more bytes in some way, but it can not be possible that it is important as the speed. .
Both appear to be very fast, but can there be a difference in speed while working with hundreds or thousands of rows?
In addition, is it possible to do SQL In an equation There are also better ways to get rid of the time part of Yaseema?
Strictly, the method A
is the least source:
a) Select DATEADD (DD, DATEDIFF (dd, 0, getdate ()), 0)
proven low CPU intensive one for the same total duration
I had seen similar tests somewhere else with similar results.
I like DateAD / DATEDIFF because:
- Walker is subject to language / date format issues Example:
- Float on internal storage
- This works on the first day of the month of tomorrow, by changing the "0" basis tomorrow
Edit, October 2011
For SQL Server 2008+, you can CAST to date
. Or simply use date
so there is no time to remove.
Edit, January 2012
This is a resilience of how it works:
Edit, May 2012
Do not understand this in this situation and even without thinking: Like adding function or CATS in column invalid the use of index. See number 2 here:
Now, the above SQL Server Adapter version is an example of managing CAST correctly, but usually will be a bad idea ...
Comments
Post a Comment