Convert a SQL Server datetime to a shorter date format

83

I have a datetime column in SQL Server that gives me data like this 10/27/2010 12:57:49 pm and I want to query this column but just have SQL Server return the day month and year - eg. 2010 10 27 or something like that.

What are the functions I should be researching?

Should I be trying to convert to another date data type? Or simply convert it to a string?

This question is tagged with sql-server tsql datetime

~ Asked on 2012-01-17 20:18:45

The Best Answer is


124

Have a look at CONVERT. The 3rd parameter is the date time style you want to convert to.

e.g.

SELECT CONVERT(VARCHAR(10), GETDATE(), 103) -- dd/MM/yyyy format

~ Answered on 2012-01-17 20:20:30


58

Try this:

print cast(getdate() as date )

~ Answered on 2014-02-19 14:09:32


Most Viewed Questions: