djskinner
djskinner

Reputation: 8125

mysql: SELECTing rows X hours old to the nearest hour

I have a clause in mysql query to select with a timestamp of 3 days ago, to the nearest day:

WHERE TO_DAYS(wit_matches.created) = TO_DAYS(NOW() - INTERVAL 3 DAY))

I want to change this so that it selects rows with a timetamp of 3 days about, but to the nearest hour - i.e. 72 hours to the nearest hour (this is a cron job that will run ones per hour).

What's the best way of achieving this?

Upvotes: 0

Views: 120

Answers (2)

danyaal
danyaal

Reputation: 1

71.5 < 72 < 72.5 it is very easy once u get the hang of it

Upvotes: -3

Sifeng
Sifeng

Reputation: 719

You can try this.

WHERE wit_matches.created BETWEEN (NOW() - INTERVAL 73 HOUR) AND (NOW() - INTERVAL 72 HOUR)

Upvotes: 1

Related Questions