I was playing with MYSQL and I know there's a limit command that shows a certain amount of results, but i was wondering if MySQL alone can show only the last 3 days or something. Just wondering.
Update: I used NOW() to store times.
We use system function now() to get the latest datetime value, and INTERVAL clause to calculate a date 7 days in the past.
SELECT * FROM product WHERE pdate >= DATEADD(day, -30, getdate()).
The DATE_ADD() function adds a time/date interval to a date and then returns the date.
Use for a date three days ago:
WHERE t.date >= DATE_ADD(CURDATE(), INTERVAL -3 DAY);
Check the DATE_ADD documentation.
Or you can use:
WHERE t.date >= ( CURDATE() - INTERVAL 3 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