dombili
dombili

Reputation: 29

Mysql - Select rows created 1 hour ago

I try to developp a cron task (PHP-MYSQL) that will be executed every 10 minutes to send an email only on the results of my query.

On this script, i would like to select the rows created 1 hour ago. I have a datetime field which contains the creation date.

How to select rows created 1 hour ago ? (without to take care of minutes and seconds)

I tried this code below but it returns me all the rows older than 1 hour, which is not what i need

SELECT email FROM clients WHERE (date_creation  < DATE_SUB(NOW(), INTERVAL 1 HOUR))

Upvotes: 2

Views: 4572

Answers (1)

Onkar Musale
Onkar Musale

Reputation: 909

You can use this query.

SELECT email FROM clients WHERE date_creation >= DATE_SUB(NOW(), INTERVAL 1 HOUR);

it will give you all records created in hour.

Upvotes: 5

Related Questions