Forum Moderators: coopster

Message Too Old, No Replies

Query for records older than a date?

         

Regent

11:48 pm on May 24, 2004 (gmt 0)

10+ Year Member



I need to write a query for a table that has records that are up to 5 years old. I need the query to return records that are older than 6 months only. There is a date field in the table. Using date_sub and interval I know how to get records between today's date and an interval, but not records older than that interval.

Thanks for any help.

select * from tables where date_checked BETWEEN DATE_SUB(CURRENT_DATE(),INTERVAL n DAY) AND CURRENT_DATE();

lorax

3:06 am on May 25, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



[dev.mysql.com...]

I would think you could use something along the lines of this for your WHERE clause:

WHERE YEAR(CURDATE()) < YEAR(CURDATE())-5

(not tested)