Select records from NOW() -1 Day

前端 未结 6 1594
没有蜡笔的小新
没有蜡笔的小新 2020-12-04 13:38

Is there a way in a MySQL statement to order records (through a date stamp) by >= NOW() -1 so all records from the day before today to the future are selected?

6条回答
  •  死守一世寂寞
    2020-12-04 14:13

    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.

提交回复
热议问题