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

To get the current date in T-SQL use the GETDATE() function. The result of the function is DateTime data type meaning, it contains both the date and the time, e.g. 2022-07-10 10:32:04.

However, to get the current date without time in T-SQL 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

Syntax to get the current date without time in T-SQL is:

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.

SELECT the Current Date Without Time in T-SQL Example

Let’s look at an example on how to select the current date without time in T-SQL.

First, we will create a demo database to run the query.

CREATE DATABASE GeeksForGeeks;
USE GeeksForGeeks;

Query:

SELECT CAST( GETDATE() AS Date )
Get the Current Date Without Time in T-SQL

Get the Current Date Without Time in T-SQL




Reffered: https://www.geeksforgeeks.org


SQL

Related
How to Connect Teradata Using SAS in SQL? How to Connect Teradata Using SAS in SQL?
What is NODUPKEY Feature in PROC SQL? What is NODUPKEY Feature in PROC SQL?
Events in MySQL Events in MySQL
Identify and Kill Queries with MySQL Command Identify and Kill Queries with MySQL Command
What is Alternative to _N_ in PROC SQL? What is Alternative to _N_ in PROC SQL?

Type:
Geek
Category:
Coding
Sub Category:
Tutorial
Uploaded by:
Admin
Views:
11