





A common function that people need to do when dealing with datetimes is extracting the date from the datetime. Oracle has a built-in function to do this called TRUNC. SQL Server does not have this (yet). However… you can accomplish this very easily. Here are a few ways to perform a truncate date function in SQL Server.
1 2 3 4 5 6 7 8 |
-- Assign date to variable DECLARE @DateToTruncate DATETIME = '2014-08-01 14:12:34' -- Get the date using casts SELECT CAST(CAST(@DateToTruncate AS DATE) AS DATETIME) -- Get the date using convert SELECT CAST(CONVERT(VARCHAR(10), @DateToTruncate, 101) AS DATETIME) |