Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

getdate() - subtract 6 months

Posted on 2009-07-01
5
1,466 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
t-sql need help on t-sql 10 25
SQL Server 2008 R2, need a pivot/cross tab query... 4 25
job schedule 8 16
SQL View / Qtry 3 8
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

792 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