I have data that has a date (Y-m-d H:i:s) column (the type is datetime). I'd like to select all records from 1 week before a date I enter (in the below example: 2011-09-17 00:00:00, but am having some trouble. Here's what I've got:
SELECT * FROM emails WHERE (DATE(date) = date_sub(date('2011-09-17 00:00:00'), 1 week))
What am I doing wrong? Thanks
Try this, I like to stick with DATE_ADD and just use a negative value.
SELECT * FROM emails WHERE date >= DATE_ADD('2011-09-17 00:00:00', INTERVAL -1 WEEK)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With