Monday, June 4, 2012

Extract Date from DateTime Field in SQL

I was working on SQL to create a view to get the reports for our subscribers and group them by day. This is fairly easy to implement in .NET, but I have been licking SQL candies for a while and so wanted to try it out. This is how I did:
 SELECT DATEADD(dd, 0, DATEDIFF(dd, 0, GETDATE()))
I could have used varchar converstion and "trimmed" the time value, but I had to further sort the resultset based upon the date obtained, so it was important for me to have it as a date type.

No comments:

There was an error in this gadget