Reputation: 445
I recorded data in field 'date' by mysql NOW() function. I want to SELECT data which recorded the last three days(today, yesterday and the day before yesterday),but no idea to do this.
SELECT * FROM tlb_students WHERE date ...?... ORDER BY date DESC LIMIT 20
Upvotes: 3
Views: 4786
Reputation: 808
Another way to do it is:
SELECT * FROM tlb_students WHERE date < DATE_ADD(CURDATE(),INTERVAL -3 DAY)
Upvotes: 1
Reputation: 23125
SELECT *
FROM tlb_students
WHERE date >= NOW() - INTERVAL 3 DAY
ORDER BY date DESC
LIMIT 20
Upvotes: 4