SQL Query to Convert DateTime to Date in SQL Server
Last Updated :
15 May, 2025
In SQL Server, working with DateTime data types can be a bit complex for beginners. This is because DateTime includes both the date and time components, while many scenarios only require the date. Whether you're working with large datasets, performing data analysis, or generating reports where time does not matter, converting DateTime to Date becomes an important task.
In this article, we will explain how to convert DateTime to Date in SQL Server using four powerful methods: CAST(), CONVERT(), TRY_CONVERT(), and SUBSTRING(). By the end of this article, we will understand how to extract the date part of a DateTime value and streamline your queries.
Why Convert DateTime to Date in SQL Server?
When working with DateTime values, there are many situations where the time component is irrelevant or unnecessary. Converting DateTime to Date can be helpful in scenarios like:
- Generating Date-Based Reports: If you're building daily, weekly, or monthly reports, you may not need to include the time portion.
- Simplifying Date Comparisons: When you need to compare dates without worrying about time, converting to just the date helps streamline the process.
- Aggregating by Date: For example, when calculating daily totals or averages, you may want to group data by date only, ignoring the time part.
Methods to Convert DateTime to Date in SQL Server
The aim of this article data is to convert DateTime to Date in SQL Server like YYYY-MM-DD HH:MM: SS to YYYY-MM-DD. Here are four common and effective methods to convert DateTime to Date in SQL Server:
1. Using CAST()
The CAST() function in SQL Server is one of the most flexible functions available. It allows you to explicitly convert one data type to another, and it's perfect for stripping off the time portion from a DateTime value. To convert a DateTime to a Date, we can use the CAST() function as shown below.
Syntax
CAST( dateToConvert AS DATE)
Example 1: Convert the current DateTime to a Date.
SELECT CAST(GETDATE() AS DATE) AS CURRENT_DATE
Output

Explanation: In this example, GETDATE() returns the current date and time, and the CAST() function converts it into a DATE type.
Example 2: Convert a specific DateTime string to a Date.
SELECT CAST('2021-08-27 17:26:36.710' AS DATE) AS CURRENT_DATE_GFG
Output

Explanation: Here, the CAST() function is used to convert a string representation of DateTime to a Date, removing the time component.
2. Using CONVERT()
The CONVERT() function is another SQL Server function that allows you to convert data types. It allows us to specify the target data type as DATE and is particularly useful when working with different date formats.
Syntax
CONVERT(DATE, dateToConvert)
Example 1: Convert the current DateTime to a Date.
SELECT CONVERT(DATE, GETDATE()) AS CURRENT_DATE_GFG
Output

Explanation: CONVERT() works similarly to CAST() but allows for different formatting options, making it a great choice when working with DateTime values in different formats.
Example 2: Convert a specific DateTime string to a Date.
SELECT CONVERT(DATE, '2021-08-27 17:26:36.710' ) AS CURRENT_DATE_GFG
Output

Explanation: The CONVERT() function efficiently converts the string DateTime to a Date, again discarding the time portion.
3. Using TRY_CONVERT()
The TRY_CONVERT() function is similar to CONVERT(), but with one key difference: if the conversion fails it returns NULL instead of throwing an error. This can be particularly useful when we are working with data integrity and error handling. This makes it ideal for scenarios where you’re working with data that might not always be in the correct format or might have unexpected values.
Syntax
TRY_CONVERT(DATE, dateToConvert)
Example 1: Convert the current DateTime to Date
SELECT TRY_CONVERT(DATE,GETDATE()) AS CURRENT_DATE_GFG
Output

Explanation: Like CONVERT(), TRY_CONVERT() can convert a DateTime value to Date, but it has the added advantage of safely handling data conversion errors.
Example 2: Convert a valid DateTime string to Date.
SELECT TRY_CONVERT(DATE,'2021-08-27 17:26:36.710') AS CURRENT_DATE_GFG
Output

Explanation: TRY_CONVERT() returns the same result as CONVERT() in this case, but it ensures that if the DateTime string was invalid or improperly formatted, the query would return NULL instead of an error.
4. Using SUBSTRING()
If we want to manually extract the date portion of a DateTime value as a string, you can use the SUBSTRING() function. This method involves getting a substring of the DateTime string, starting from the 0th index and selecting only the first 10 characters (YYYY-MM-DD). This method is not the most common approach, but it can be useful in certain situations
Syntax
SUBSTRING( dateToConvert ,0,11)
SELECT SUBSTRING( '2021-08-27 17:26:36.710' ,0,11) AS CURRENT_DATE_GFG
Output

Explanation: Here, the SUBSTRING() function extracts the first 10 characters (the date part) of the DateTime string. This method can be useful when working with formatted strings.
SELECT SUBSTRING( CONVERT(varchar(17), GETDATE(), 23) ,0,11) AS CURRENT_DATE_GFG
Output

Explanation: In this example, we first CONVERT() the current DateTime to a varchar string with format 23 (YYYY-MM-DD), then use SUBSTRING() to get only the date part.
Conclusion
Converting DateTime to Date in SQL Server is a straightforward process that can help simplify our queries by focusing only on the date portion of the value. Whether we're using CAST(), CONVERT(), TRY_CONVERT(), or SUBSTRING(), each method allows us to effectively manage DateTime values in our SQL queries. By choosing the appropriate method for our use case, we can enhance query performance, improve data analysis, and generate accurate reports without the need for time-related data.
Similar Reads
SQL Query to Convert Date to Datetime
In this article, we will look at how to convert Date to Datetime. We can convert the Date into Datetime in two ways. Using CONVERT() function: Convert means to change the form or value of something. The CONVERT() function in the SQL server is used to convert a value of one type to another type.Conve
1 min read
SQL Query to Convert Datetime to String
In order to convert a DateTime to a string, we can use CONVERT() and CAST() function. These functions are used to converts a value(of any datatype) into a specified datatype. CONVERT() Function Syntax: CONVERT(VARCHAR, datetime [,style])VARCHAR - It represent the string type.datetime - It can be the
3 min read
SQL Query to Convert Date Range to Per Day Records
In this article, we are going to see how we can convert the date range to per day records, but before that, we need to have a clear idea of where it is going to be helpful for us. Suppose, We have a database where we want to store all the project details records of the students of a particular class
5 min read
SQL Query to Convert Datetime to Epoch
Converting a datetime value to Epoch time is a common operation in SQL, particularly when working with timestamps in various applications. In this article, We will learn a step-by-step process of creating a SQL database, inserting datetime values and converting those values into Epoch time using SQL
3 min read
How to Convert DateTime to VarChar in SQL Server
In SQL Server, date and time values are often stored in the DATETIME or DATE data types. However, there are situations where we may want to convert these values into a different format such as VARCHAR to display the date in a specific format or for further manipulation.In this article, we will explo
4 min read
Convert Date To Datetime In Python
When you're programming, dealing with dates and times is important, and Python provides tools to manage them well. This article is about changing dates into date times in Python. We'll explore methods that can help you switch between these two types of data. Whether you're building a website or work
3 min read
SQL Query to Convert Rows to Columns in SQL Server
In this article we will see, how to convert Rows to Column in SQL Server. In a table where many columns have the have same data for many entries in the table, it is advisable to convert the rows to column. This will help to reduce the table and make the table more readable. For example, Suppose we h
2 min read
SQL Query to Convert Date Field to UTC
In SQL, dates are complicated for newbies, since while working with the database, the format of the date in the table must be matched with the input date in order to insert. In various scenarios instead of date, DateTime (time is also involved with date) is used. In this article, we will discuss how
2 min read
How to Convert Datetime to Date in Pandas ?
DateTime is a collection of dates and times in the format of "yyyy-mm-dd HH:MM:SS" where yyyy-mm-dd is referred to as the date and HH:MM:SS is referred to as Time. In this article, we are going to discuss converting DateTime to date in pandas. For that, we will extract the only date from DateTime us
4 min read
How to convert datetime to date in Python
In this article, we are going to see how to convert DateTime to date in Python. For this, we will use the strptime() method and Pandas module. This method is used to create a DateTime object from a string. Then we will extract the date from the DateTime object using the date() function and dt.date f
3 min read