开发者

How do I compare a datetime field to a time expressed in minutes using MySQL

开发者 https://www.devze.com 2023-01-31 16:57 出处:网络
I want to select a row only if it is younger than a set time, in this case 5 minutes: I\'m not sure how to tell MySQL that 5 is minutes, and not an int. As such, I can\'t do this:

I want to select a row only if it is younger than a set time, in this case 5 minutes: I'm not sure how to tell MySQL that 5 is minutes, and not an int. As such, I can't do this:

SELECT data from 开发者_JAVA百科dataTable WHERE data.createdAt < 5

createdAt is a datetime field.


This should do the job:

SELECT data FROM dataTable 
            WHERE data.createdAt > DATE_SUB(NOW(), INTERVAL 5 MINUTE)
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号