Brandon Brandon - 4 months ago 13
SQL Question

Converting getdate() to yyyymmdd

I have found a couple of different methods to convert it. However, I still get the

yyyy-mm-dd
format or
yyyy-mm-dd hh:mm:ss
. I am currently using SQL Server 2014.

SELECT dateadd(day, convert(int, getdate()), 112)
SELECT DATEADD(YEAR, -2, convert(DATE, GETDATE(), 112))


It would be nice if you guys can help me out because this is pretty urgent for me.

Answer

You can also use FORMAT:

 select FORMAT(getdate(), 'yyyyMMdd')
Comments