Brandon Brandon - 1 year ago 60
SQL Question

Converting getdate() to yyyymmdd & getting the date two years back

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

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

SELECT dateadd(day, convert(int, getdate()), 112)

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

Thanks a lot guys for the quick reply. So right now I am doing a date range of 2 years. Thus I need the codes to the find the date two years back.

Answer Source

You can also use FORMAT:

 select FORMAT(getdate(), 'yyyyMMdd')
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download