If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > MySQL DATETIME select query help

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-07-05, 16:02
psalzmann psalzmann is offline
Registered User
 
Join Date: Feb 2005
Posts: 7
Question 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
Reply With Quote
  #2 (permalink)  
Old 02-07-05, 17:02
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
Code:
 ... 
 where yourtable.`Date`
       between date_add(current_date, interval 7 day)
           and current_date
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 02-08-05, 22:26
psalzmann psalzmann is offline
Registered User
 
Join Date: Feb 2005
Posts: 7
Thumbs up

r937,

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

Peter
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On