I have a SQL statement that expected to select all the days at least seven days before today
I used the code as follows:
SELECT * FROM letter WHERE letter.l_date > DATE_SUB(CURDATE(), INTERVAL 7 DAY)
But did not get the desired result. I can not understand what I am going wrong. Can anyone help me Pls.?
So if you want it just from the last seven days including today, you need to specify that l_date is before now:
SELECT * FROM letter WHERE letter.l_date < DATE_SUB(CURDATE(), INTERVAL 7 DAY)
if you need last 7 days data use DATE(NOW()) - INTERVAL 7 DAY
SELECT * FROM letter WHERE letter.l_date > DATE(NOW()) - INTERVAL 7 DAY
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