Solved

sql: current date - 60?

Posted on 2010-08-16
6
351 Views
Last Modified: 2012-05-10
hi all

i want to update data 3 months older than the current date

how can i do this?
0
Comment
Question by:malraff
6 Comments
 
LVL 6

Expert Comment

by:Ashok Kumar
ID: 33444666
DATEDIFF(month, @date, getdate())<3
something like this.
0
 
LVL 3

Expert Comment

by:mamalik00
ID: 33444667
MSSql Server

 select datepart(mm,getdate()) - 3
 
this query will return you the current month - 3
0
 
LVL 6

Expert Comment

by:Ashok Kumar
ID: 33444670
you need to use the condition in your update where clause.
0
Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 33444672
>3 months older
as suggested by above comments, please clarify what exactly means "3 months" ...


"exactly" 3 months ago:
dateadd(month, -3, getdate())


however, you might want to take only full months ?
0
 
LVL 13

Expert Comment

by:Philip Pinnell
ID: 33444678
update yourtable
set yourfield=value
where datefield < dateadd(mm,-3,getdate() )
0
 

Author Comment

by:malraff
ID: 33444735

 select datepart(mm,getdate()) - 3 still returned 2010-08-05 00:00:00.000

angel -- yours works 100%, i want exactly 3 months as you provided!
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This article will describe one method to parse a delimited string into a table of data.   Why would I do that you ask?  Let's say that you need to pass multiple parameters into a stored procedure to search for.  For our sake, we'll say that we wa…
Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

760 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

19 Experts available now in Live!

Get 1:1 Help Now