?
Solved

select where date is > 5 days ago

Posted on 2003-11-11
3
Medium Priority
?
373 Views
Last Modified: 2010-04-17
I'm trying to select (in sql) where a value is > {fn NOW()-5}. That is, matches where the value is greater than 5 days ago, but my function-5 is incorrect. I'd appreciate any suggestions to do this. Thank you.
0
Comment
Question by:cwest1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 6

Accepted Solution

by:
pillbug22 earned 500 total points
ID: 9725465
Try the DATEDIFF() function:

SELECT id, name FROM myTable WHERE (DATEDIFF(day, lastUpdated, GETDATE()) <= 5)
0
 
LVL 6

Expert Comment

by:pillbug22
ID: 9725479
edit for above:

"day" is the length of time you are comparing for - can be changed to day, month, week, year, etc.

"lastUpdated" should be the SQL table field you are wanting to compare to today.
0
 

Author Comment

by:cwest1
ID: 9725536
like a charm. thanks
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
This article will show how Aten was able to supply easy management and control for Artear's video walls and wide range display configurations of their newsroom.
Six Sigma Control Plans
Progress

770 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