GETDATE -1 or 2

user2646056 picture user2646056 · Aug 2, 2013 · Viewed 28.6k times · Source

With this:

CONVERT(varchar(10),DATEADD(month,1,GETDATE()),120)

I get this

2013-08-19

which is perfect but I need it to output one or two days less

example: 2013-08-18

Any tips?

Answer

Rccompton picture Rccompton · Aug 2, 2013

For 1 day less you could use

Select CONVERT(varchar(10),(dateadd(dd, -1, getdate())),120)

or for 2 days difference use

Select CONVERT(varchar(10),(dateadd(dd, -2, getdate())),120)

The convert will make it the format you seek and the dateadd will change the dd or day with -1 or 2 whichever you are wanting to use at that time.