简体   繁体   中英

How to SELECT data from table only recorded the last three days

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
WHERE date >= ( CURDATE() - INTERVAL 3 DAY )
SELECT * 
FROM tlb_students 
WHERE date >= NOW() - INTERVAL 3 DAY
ORDER BY date DESC
LIMIT 20
WHERE date >= subdate(NOW(), 2) 

Another way to do it is:

SELECT * FROM tlb_students WHERE date < DATE_ADD(CURDATE(),INTERVAL -3 DAY)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM