Join us in Las Vegas on June 13-16 for the Snowflake Summit

Learn More

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

A Faster Way To Build Data Models

Mix SQL and no code to create data models in a few clicks vs months.

Try Datameer Today


Up Next:

Read How to add an IDENTITY to an existing column in SQL

More Resources We Think You Might Like

SQL FAQ Feat

How to concatenate data from different rows of ...

Let us consider the following table: CREATE TABLE fruits (     ID INT,     NAME VARCHAR(50) ) INS...

  • How-Tos FAQs
  • December 16, 2018
SQL FAQ Feat

How to calculate percentage in SQL?

There are different ways to calculate percentage in SQL like  Using OVER() clause Using subquery ...

  • How-Tos FAQs
  • December 17, 2018
SQL FAQ Feat

How to display the tables containing particular...

We can list all the tables with particular strings using the LIKE operator. Display tables contai...

  • How-Tos FAQs
  • December 17, 2018