Forum Moderators: open

Message Too Old, No Replies

How do I Select All Rows from a Specific Date Range?

         

Tehuti

10:24 pm on Sep 15, 2008 (gmt 0)

10+ Year Member Top Contributors Of The Month



Whenever I add a new row of data to my database, I give it an expiration date (e.g., 2008-10-01).

I know how to select all the rows that I have added in the past 3 days:

SELECT * FROM table WHERE DATE_SUB(CURDATE(),INTERVAL 30 DAY) <= date_column;

However, I can't figure out how to select all the rows that are due to expire in the next 3 days (today, tomorrow or the day after)? Can anyone help, please?

rocknbil

3:27 pm on Sep 16, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



select * from table where date_column >= curdate() and date_column <= date_add(curdate(),interval 2 day);

"2 day" if you consider today as one of the three days. If the first day you want to query is tomorrow,

select * from table where date_column > curdate() and date_column <= date_add(curdate(),interval 3 day);

Tehuti

5:25 am on Sep 22, 2008 (gmt 0)

10+ Year Member Top Contributors Of The Month



Thanks, Rocknbil!