How to extract date from a DateNow() in YYYYMMDD format in SQL Server

Sree picture Sree · Jan 21, 2014 · Viewed 13.9k times · Source

Got a specific requirement that we should extract only date and in YYYYMMDD format from GETDATE() in Sql-Server 2005.

How can I accomplish this.

Thanks

Answer

Jerodev picture Jerodev · Jan 21, 2014

You can use formatting in your sql query: http://www.sql-server-helper.com/tips/date-formats.aspx

Your query should be

SELECT CONVERT(VARCHAR(8), GETDATE(), 112) AS [YYYYMMDD]