ASP.NET Cafe
new tricks every week

MS SQL. How to get only date from datetime field

Tuesday, 4 November 2008 09: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

Comments

Add comment


 

  Country flag

biuquote
  • Comment
  • Preview
Loading