Welcome to deBUG.to Community where you can ask questions and receive answers from Microsoft MVPs and other experts in our community.
1 like 0 dislike
in SQL Queries by 23 55 69

I have cloumn in my Database in SQL Server with DateTime datatype, when i query that cloumn it's return:

2023-09-18 00:00:00.0000000

I want only the date which is the first part "2023-09-18". 

How To Get Date from DateTime cloumn in SQL Server?

1 Answer

2 like 0 dislike
by 23 55 69
Best answer

Get Date from Datetime SQL

There is two way to get Date from Datetime in SQL server:

1. CAST function
CAST : convert from one data type to another.
Syntax : CAST(expression AS data_type)

SELECT CAST(datetime_column AS DATE) FROM table_name;

2. CONVERT function
CONVERT: converts a value from one data type to another.
Syntax: CONVERT(data_type, expression)

SELECT CONVERT(DATE, datetime_column) FROM table_name;
If you don’t ask, the answer is always NO!