Reputation: 565
How can I fetch rows that are now older than three days?
The dates are stored in a format like this 2018-12-06
for the 6th of December 2018
Upvotes: 2
Views: 1146
Reputation: 32003
You have an invalid condition. Try it like this:
SELECT * FROM posts
where date(creation_date) >=DATE_ADD(CURDATE(), INTERVAL -3 DAY)
and date(creation_date) <=curdate()
ORDER BY id DESC
Here I used DATE_ADD
function to go back 3 days
Upvotes: 0
Reputation: 38502
Not tested but you need something like this,
SELECT * FROM posts WHERE creation_date >= (DATE(NOW()) - INTERVAL 3 DAY) ORDER BY id DESC
For mysql syntax and date function
Upvotes: 3