SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Wizard
    Join Date
    Mar 2008
    Location
    United Kingdom
    Posts
    1,285
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    SELECT records published in last 5 days?

    Hi,

    I have a column in a table that stores the date (say, 2009-08-31 11:08:19).

    Now, I'd like to do a SQL Query which would throw up TRUE if that date is either equal to, or in the past 5 days.

    Does this make sense?

    so if I had

    id | name | date_added
    1 | jake | 2009-08-31 11:08:19

    and if today was 2009-09-02 then it would give me a result.


    I did have something like this, but it didn't work

    PHP Code:
    SELECT DISTINCT name FROM groups WHERE date_added >= (NOW()-7
    Any ideas where to start?

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,250
    Mentioned
    59 Post(s)
    Tagged
    3 Thread(s)
    Code:
    WHERE date_added >= CURRENT_DATE - INTERVAL 5 DAY
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Wizard
    Join Date
    Mar 2008
    Location
    United Kingdom
    Posts
    1,285
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Brilliant!!!!

    Many, many thanks sir. How easy was that, when you know how


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •