Date Truncation in SQL Server
Writing by shivdev on Tuesday, 25 of March , 2008 at 11:47 am
Need to trunc dates in SQL Server? Follow the examples below.
SELECT DATEADD(HOUR, DATEDIFF(HOUR, 0, GETDATE()), 0) -- 2008-03-25 10:00:00.000 SELECT DATEADD(DAY, DATEDIFF(DAY, 0, GETDATE()), 0) -- 2008-03-25 00:00:00.000 SELECT DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE()), 0) -- 2008-03-01 00:00:00.000 SELECT DATEADD(YEAR, DATEDIFF(YEAR, 0, GETDATE()), 0) -- 2008-01-01 00:00:00.000
Leave a comment
Category: SQL DB
- Add this post to
- Del.icio.us -
- Digg -
- -
- Tweet -
-
-