DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Jason has posted 22 posts at DZone. View Full User Profile

Remove Time From A SQL Date

01.09.2009
| 10526 views |
  • submit to reddit
        Convert a SQL date time into a date, aka, remove time from a SQL date

-- fast way that relies on the internal data structure
SELECT CAST( FLOOR( CAST( GETDATE() AS FLOAT ) ) AS DATETIME ) AS date_only

-- slower way that does not rely on internal data structure
SELECT CONVERT( DATETIME, CONVERT( NCHAR(10), GETDATE(), 126 ) ) AS date_only