简体   繁体   中英

How to get last 3 days records from database without today?

I am using this code:

WHERE date > DATE_SUB(CURDATE(), INTERVAL 3 DAY)

And result will be like this:

2022-05-12
2022-05-11
2022-05-10

But I want this:

2022-05-11
2022-05-10
2022-05-09

Use a range here:

WHERE date < CURDATE() AND date >= DATE_SUB(CURDATE(), INTERVAL 3 DAY)

Assuming today's date be 2022-05-12 , the above logic would exclude this date but include the three previous days, from 11th May to 9th May.

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