Return date as ddmmyyyy in SQL Server

Matt picture Matt · Jul 21, 2011 · Viewed 129.8k times · Source

I need the date as ddmmyyyy without any spacers.

How can I do this?

I can get yyyymmdd using CONVERT(VARCHAR, [MyDateTime], 112)

But I need the reverse of this.

SQL Server 2008

Answer

Joe Stefanelli picture Joe Stefanelli · Jul 21, 2011

CONVERT style 103 is dd/mm/yyyy. Then use the REPLACE function to eliminate the slashes.

SELECT REPLACE(CONVERT(CHAR(10), [MyDateTime], 103), '/', '')