SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Date Comparison
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

eimpact
Starting Member

2 Posts

Posted - 12/10/2012 :  21:55:01  Show Profile  Reply with Quote
Hello,

I have a scheduled task running every hour that is supposed to return records with dates that are 3 days old (or older) and I need it to be considerate of the minutes. The following is an example of the format of the date:

2012-12-04 21:18:08.273

Can someone help me with the query?

LoztInSpace
Aged Yak Warrior

940 Posts

Posted - 12/10/2012 :  22:42:29  Show Profile  Reply with Quote
where [yourDateColumn] <= getdate()-3
will return everything 3 days or older. Not sure what you mean "considerate of the minutes". "Older" is relative to a point in time considerate of everything. If what you mean is to disregard certain bits of the time then look at
DATEPART to get out the various components
and then use
DATEADD to remove the bits you are not interested in e.g. this removes milliseconds:
select dateadd(ms,-datepart(ms,getdate()), getdate()-3)

the rest is an exercise to the reader :)
Go to Top of Page

eimpact
Starting Member

2 Posts

Posted - 12/10/2012 :  22:59:25  Show Profile  Reply with Quote
I'm not looking to disregard any part of the date...the exact opposite actualy. If the date in the column is 12/10/2012 at 1:05 PM, I don't want it to return that record until 12/13/2012 at 1:05 PM (or after). If this simple where clause will do that:

where [yourDateColumn] <= getdate()-3

...then that's all I need! I was concerned that a simple comparison would start returning this record at 12/13/2012 at 12:01 AM.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000