Welcome to deBUG.to Community where you can ask questions and receive answers from Microsoft MVPs and other experts in our community.
2 like 0 dislike
779 views
in SQL Queries by 66 69 85

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

3 like 0 dislike
by 66 69 85
 
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)
Example:

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)
Example:

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