Solved

getdate() - subtract 6 months

Posted on 2009-07-01
5
1,452 Views
Last Modified: 2012-05-07
I am using getdate() to return todays date.

How am i able to use getdate() and subtract 6 months from it?
0
Comment
Question by:Mr_Shaw
5 Comments
 
LVL 60

Accepted Solution

by:
chapmandew earned 200 total points
ID: 24755056
select dateadd(m, -6, getdate())
0
 
LVL 10

Expert Comment

by:dwe761
ID: 24755089
select dateadd(m,6, getdate())
0
 
LVL 10

Assisted Solution

by:dwe761
dwe761 earned 150 total points
ID: 24755112
I concede.  I went ahead 6 months.  chapmandew is correct.
0
 
LVL 26

Assisted Solution

by:Chris Luttrell
Chris Luttrell earned 150 total points
ID: 24755180
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
 

Author Closing Comment

by:Mr_Shaw
ID: 31598796
thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now