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))
I am doing a date range of 2 years. Thus I need the codes to the find the date two years back.
You can also use FORMAT:
select FORMAT(getdate(), 'yyyyMMdd')
Try CONVERT(char(8), GETDATE(), 112)
Also check https://technet.microsoft.com/en-us/library/ms187928(v=sql.105).aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With