SELECT GETDATE()
Returns: 2008-09-22 15:24:13.790
I want that date part without the time part: 2008-09-22 00:00:00.000
How can I get that?
SELECT GETDATE()
Returns: 2008-09-22 15:24:13.790
I want that date part without the time part: 2008-09-22 00:00:00.000
How can I get that?
If you are assigning the results to a column or variable, give it the DATE type, and the conversion is implicit.
On
SQL Server 2008
and higher, you shouldCONVERT
to date:On older versions, you can do the following:
for example
gives me
Pros:
varchar
<->datetime
conversions requiredlocale
If you are using SQL Server 2012 or above versions,
Use
Format()
function.There are already multiple answers and formatting types for SQL server. But most of the methods are somewhat ambiguous and it would be difficult for you to remember the numbers for format type or functions with respect to Specific Date Format. That's why in next versions of SQL server there is better option.
Culture option is very useful, as you can specify date as per your viewers.
You have to remember d (for small patterns) and D (for long patterns).
1."d" - Short date pattern.
2."D" - Long date pattern.
More examples in query.
If you want more formats, you can go to:
On SQL Server 2000
If using SQL 2008 and above: