SQL tip

May 22, 2008

Quick SQL tip that I find useful. If you want just the date part of a datetime value, the following neat expression yields it:

SELECT DATEADD(d, 0, DATEDIFF(d, 0, datetime_column))

This is useful for comparing dates. Alternative approaches include casting to string, and comparing the date parts (day, month, year) separately. The context determines which is most appropriate.

Gently provided by SK.

  • Facebook
  • Twitter
  • RSS
  • Google Bookmarks
  • email
  • Digg
Posted by whit3kr0w | Categories: Programming | Tagged: , |

No Responses so far | Have Your Say!

Leave a Feedback

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>