Convert a SQL Server datetime to a shorter date format

Solution 1:

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

Solution 2:

Try this:

print cast(getdate() as date )

Solution 3:

If you need the result in a date format you can use:

Select Convert(DateTime, Convert(VarChar, GetDate(), 101))

Solution 4:

In addition to CAST and CONVERT, if you are using Sql Server 2008, you can convert to a date type (or use that type to start with), and then optionally convert again to a varchar:

declare @myDate date
set @myDate = getdate()
print cast(@myDate as varchar(10))

output:

2012-01-17