Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
eimpact
Starting Member
2 Posts |
Posted - 2012-12-10 : 21:55:01
|
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.273Can someone help me with the query? |
|
LoztInSpace
Aged Yak Warrior
940 Posts |
Posted - 2012-12-10 : 22:42:29
|
where [yourDateColumn] <= getdate()-3will 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 componentsand 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 :) |
|
|
eimpact
Starting Member
2 Posts |
Posted - 2012-12-10 : 22:59:25
|
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. |
|
|
|
|
|