Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

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

Starting Member

2 Posts

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

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?

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

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  
 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