Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2005
    Posts
    7

    Question Unanswered: MySQL DATETIME select query help

    Greetings everyone. I noticed the amount of database discussion on this site and decided to join up! Excellent stuff.

    I am trying to issue a query that will return rows from a mysql database giving me results from exactly 1 week ago (to the present day) (via DATETIME field).

    Basically, I have:

    ID | Date | Status
    ------------------
    1 | 2005-02-01 00:00:00 | Open
    2 | 2005-01-25 00:00:00 | Closed
    3 | 2005-02-01 00:00:00 | Finished
    etc.........

    From the example above, I would want to see ID's 1 and 3 as the rows returned as they are basically last week (from the 1st, today is the 7th)..

    Any help would be highly appreciated.

    Thanks in advance!

    Peter

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Code:
     ... 
     where yourtable.`Date`
           between date_add(current_date, interval 7 day)
               and current_date
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Feb 2005
    Posts
    7

    Thumbs up

    r937,

    That query works very nicely for what I'm doing.
    Thank you very much

    Peter

Posting Permissions

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