Fetching rows added last hour

后端 未结 6 1924
北海茫月
北海茫月 2020-12-14 05:20

I keep a record of logins in a table. I have columns for id, ip, date and time. From that record of logins I wanna fetch logins made only in the last hour.

I\'m swe

6条回答
  •  粉色の甜心
    2020-12-14 06:05

    If you want to implement this into a cronjob, you need to specify the start and end.

    For example, at 2pm, if you want to get the data for the past hour from 13:00:00 until 13:59:59, here's how to do it:

    dateField BETWEEN 
    DATE_FORMAT(DATE_SUB(NOW(), INTERVAL 1 HOUR), '%Y-%m-%d %H:00:00') 
    AND 
    DATE_FORMAT(DATE_SUB(NOW(), INTERVAL 1 HOUR), '%Y-%m-%d %H:59:59')
    

提交回复
热议问题