[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1551
  • Last Modified:

getdate() - subtract 6 months

I am using getdate() to return todays date.

How am i able to use getdate() and subtract 6 months from it?
0
Mr_Shaw
Asked:
Mr_Shaw
3 Solutions
 
chapmandewCommented:
select dateadd(m, -6, getdate())
0
 
dwe761Software EngineerCommented:
select dateadd(m,6, getdate())
0
 
dwe761Software EngineerCommented:
I concede.  I went ahead 6 months.  chapmandew is correct.
0
 
Chris LuttrellSenior Database ArchitectCommented:
chapmandew has the correct syntax to subtract 6 months.  The other one add 6 months.
Remember that getdate() will include the time portion and the dateadd function will change the date part and leave the time alone.  If you want the start of the day you have to use code like this for todays date:
select dateadd(d,datediff(d,0,getdate()),0)

and this for 6 months ago:
select dateadd(m, -6, dateadd(d,datediff(d,0,getdate()),0))
0
 
Mr_ShawAuthor Commented:
thanks
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now