Solved

select where date is > 5 days ago

Posted on 2003-11-11
3
326 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

762 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now