
How to get only the DATE part from the DATETIME in SQL Server?
- How-Tos FAQs
- February 1, 2019
In SQL Server 2008 and above, we can either use the CONVERT or CAST function to return the DATE part from the DATETIME datatype.
-- using CONVERT function
SELECT CONVERT(DATE, '2010-12-20 22:52:43.133') DateOnly
-- using CAST function
SELECT CAST('2010-12-20 22:52:43.133' AS DATE) DateOnly
-- Output
DateOnly
---------------
2010-12-20
In the older version of SQL Server, we can use a combination of DATEADD and DATEDIFF.
-- using DATEADD and DATEDIFF function
SELECT DATEADD(dd, 0, DATEDIFF(dd, 0, '2010-12-20 22:52:43.133'))
-- Output
DateOnly
--------------------------
2010-12-20 00:00:00.000