Solved

select where date is > 5 days ago

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Excel object stays open 19 70
array6 challenfge 6 81
mapBully challenge 6 113
Magic Software info 18 124
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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…

929 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

12 Experts available now in Live!

Get 1:1 Help Now