A Better Way To Extract Date From DateTime Columns [SQL Server]
- by Gopinath
Quite a long ago I wrote about a SQL Server programming tip on how to extract date part from a DATETIME column. The post discusses about using of T SQL function convert() to get date part. One of the readers of the post, tipped me about a better way of extracting date part and here is the SQL query he sent to us
SELECT DateAdd(day, DateDiff(day, 0, getdate()), 0);
In clean way this query trims off time part from the DATETIME value. I rate this solution better than the one I wrote long ago as this one does not depend on any string operations. According the commenter, this method is faster compared to the other. What do you say?
Thanks Yamo
This article titled,A Better Way To Extract Date From DateTime Columns [SQL Server], was originally published at Tech Dreams. Grab our rss feed or fan us on Facebook to get updates from us.