SQL - 1 - Strip time away from date

[MS SQL Server 2005]

Sometimes (often) a date column has an unnecessary time portion. This can complicate searches and the like, so you may wish to strip away that time portion … leaving just the dates (with a time of 12:00AM).

How this works is first it compares the target date with a date of zero … returning the number of days. It then takes this number of days and adds it to a date of zero, and sets the target date to that. Simples.

For bonus points this could be wrapped into a simple scalar-value function:

… and can be used thus:


Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License