开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜