How to get only the DATE part from the DATETIME in SQL Server and Snowflake

  • How-Tos FAQs
  • February 1, 2019

Follow along for a few different methods on how to get only DATE from the DATETIME in SQL Server

1. A Low-Code Method Using Datameer (On Snowflake)

Wondering if there is a way to get only DATE from the DATETIME in SQL Server with just a line of code?

The answer is Datameer; a multi-persona SaaS data transformation tool that caters to your data modeling and transformations needs within Snowflake.

With Datameer, you won’t need to worry about memorizing SQL functions like in the below examples.

Datameer has a rich catalog with easy-to-use functions; this includes the in-built “TODATE”  function that can extract the date from a timestamp and output the correct date format in a matter of seconds.

2. CONVERT or CAST function

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


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

2010-12-20 00:00:00.000

Up Next:

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