Solved

select where date is > 5 days ago

Posted on 2003-11-11
3
345 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
  • 2
3 Comments
 
LVL 6

Accepted Solution

by:
pillbug22 earned 125 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

786 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