Home >> FAQs/Tutorials >> SQL Server FAQ
SQL Server FAQ - Truncating DATETIME Values to Dates without Time
(Continued from previous topic...)
How To Truncate DATETIME Values to Dates without Time?
Assuming that you have some date and time, DATETIME, values,
and you want to work with dates only. You want to truncate them to dates without time,
or with time of 00:00:00.000.
Again, SQL Server offers no simple solution, you need to write the formula yourself.
The tutorial exercise below shows you how to do this with CONVERT() and FLOOR() functions:
-- truncating to dates
DECLARE @local_time DATETIME;
SET @local_time = 'May 19 2007 10:06PM';
SELECT 'Server local date and time: ';
SELECT 'Server local date without time: ';
Server local date and time:
Server local date without time:
(Continued on next topic...)
- How To Add or Remove Days on Date and Time Values?
- Can Date and Time Values Be Converted into Integers?
- Can Integers Be Converted into Date and Time Values?
- Are DATETIME and NUMERIC Values Convertible?
- Can a DATETIME Value Be Subtracted from Another DATETIME Value?
- What Are the Date and Time Functions Supported by SQL Server 2005?
- How To Increment or Decrement Parts of DATETIME Values?
- How To Use DATEADD() Function?
- How To Calculate DATETIME Value Differences Using the DATEDIFF() Function?
- How To Calculate Age in Days, Hours and Minutes?
- How To Get Month and Weekday Names from DATETIME Values?
- How To Get Parts of DATETIME Values as Integers?
- How To Get Year, Month and Day Out of DATETIME Values?
- What Is the Difference Between GETDATE() and GETUTCDATE()?
- How To Format Time Zone in +/-hh:mm Format?
- How To Format DATETIME Values to Strings with the CONVERT() Function?
- How To Truncate DATETIME Values to Dates without Time?
- How To Set Different Parts of a DATETIME Value?