Solved

sql: current date - 60?

Posted on 2010-08-16
6
360 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Stored Procedure error 45 48
Getting the 3 middle digits 4 36
SQL Backup skipping a few tables 7 36
Caste datetime 2 52
In this article I will describe the Backup & Restore 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.
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

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

17 Experts available now in Live!

Get 1:1 Help Now