A blog about gadgets, media and all technology related ’stuff’. Be a geek for a few minutes ;)

SQL tip

May 22nd, 2008 by whit3kr0w

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.

Posted in Programming

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.