Mohamad
Mohamad

Reputation: 35349

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 dataTable WHERE data.createdAt < 5

createdAt is a datetime field.

Upvotes: 0

Views: 702

Answers (1)

Pekka
Pekka

Reputation: 449613

This should do the job:

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

Upvotes: 2

Related Questions