Select records from NOW() -1 Day Select records from NOW() -1 Day mysql mysql

Select records from NOW() -1 Day


Judging by the documentation for date/time functions, you should be able to do something like:

SELECT * FROM FOOWHERE MY_DATE_FIELD >= NOW() - INTERVAL 1 DAY


Be aware that the result may be slightly different than you expect.

NOW() returns a DATETIME.

And INTERVAL works as named, e.g. INTERVAL 1 DAY = 24 hours.

So if your script is cron'd to run at 03:00, it will miss the first three hours of records from the 'oldest' day.

To get the whole day use CURDATE() - INTERVAL 1 DAY. This will get back to the beginning of the previous day regardless of when the script is run.


You're almost there: it's NOW() - INTERVAL 1 DAY