Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1521
  • 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
 
dwe761Commented:
select dateadd(m,6, getdate())
0
 
dwe761Commented:
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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