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)
精彩评论