Collections:
Truncating DATETIME Values to Dates without Time in SQL Server
How To Truncate DATETIME Values to Dates without Time in SQL Server Transact-SQL?
✍: FYIcenter.com
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 @local_time; SELECT 'Server local date without time: '; SELECT CONVERT(DATETIME, FLOOR(CONVERT(NUMERIC(18,9),@local_time))); GO Server local date and time: 2007-05-19 22:06:00.000 Server local date without time: 2007-05-19 00:00:00.000
⇒ Setting New Values to Parts of a DATETIME Value in SQL Server
⇐ CONVERT() - Formatting DATETIME Values to Strings in SQL Server
⇑ Date/Time Operations and Functions in SQL Server Transact-SQL
2017-02-08, 2746🔥, 0💬
Popular Posts:
How To View Data Files in the Current Database in Oracle? If you want to get a list of all tablespac...
What is SQL Server Transact-SQL (T-SQL)? SQL Server Transact-SQL, also called T-SQL, is an extension...
How AdventureWorksLT tables are related in SQL Server? There are 12 user tables defined in Adventure...
How To Look at the Current SQL*Plus System Settings in Oracle? If you want to see the current values...
How To End a Stored Procedure Properly in SQL Server Transact-SQL? Where the end of the "CREATE PROC...