ASP.NET Cafe
Tips and Tricks

MS SQL. How to get only date from datetime field

Tuesday, 4 November 2008 14:25 by dmitriy
And another quick tip for SQL. Sometimes we need to remove TIME part from DATETIME. For example need to group by date or so. You know your needs better.
 
Here is my solution. 
DATEADD(day, DATEDIFF(day, '20000101', RecDate), '20000101')
 
I saw some freaky CASTs and I don't like these. This returns DateTime type, not string. 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags:  
Categories:   SQL
Actions: E-mail | del.icio.us | Kick it! | DZone it! | Permalink | Comments (0) | Comment RSSRSS comment feed

Add comment


(Will show your Gravatar icon)  

  Country flag

[b][/b] - [i][/i] - [u][/u]- [quote][/quote]



Preview

January 6. 2009 15:26