Open In App

How To Get the Current Date (Without Time) in T-SQL?

Last Updated : 14 Feb, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

In this article, we will see, how to get the current date and time in SQL Server. We can perform the task by using GETDATE() function. The result of the function is DateTime data type; in other words, it contains both the date and the time, e.g. 2022-07-10 10:32:04. (Note: This function doesn’t take any arguments, so you don’t have to put anything in the brackets.)

However, if we want to get just the current date – not the date and the time – we can use the CAST() function. This function takes any expression or any column name as the first argument. Then you use the keyword AS and enter the new data type to return. (The returned value(s) could be column values or the result returned by the expression.)

Syntax:

SELECT CAST( GETDATE() AS Date ) ;

We’ll use the GETDATE() function to get the current date and time. Then we’ll use the CAST() function to convert the returned DateTime data type into a date data type.

Now, for the demonstration follow the below steps:

Step 1: Create a database

we can use the following command to create a database called GeeksForGeeks.

Query:

CREATE DATABASE GeeksForGeeks;

 

Step 2: Use the database

Use the below SQL statement to change the database to GeeksForGeeks:

Query:

USE GeeksForGeeks;

 

Step 3: 

In this example, the function GETDATE() returned the current date and time as 2022-10-07 07:42:40.357. By using CAST() with GETDATE(), the query below returned only the date 2022-10-07.

Query:

Select GETDATE()
SELECT CAST( GETDATE() AS Date )

 


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads