Xtal
Xtal

Reputation: 305

select timestamp older than

How can I select items from a database that are older than 12 hours? I am using a timestamp column to store the time but I don't think I need year, month, or day, only hours.
I have something like this but it doesn't work (no error just returning all data from table)

$sql = "SELECT *FROM Y WHERE X and time > now() - INTERVAL 12 HOUR";

You're right Salman A .Thanks

Upvotes: 6

Views: 7344

Answers (1)

Manse
Manse

Reputation: 38147

Try this :

SELECT * FROM Y WHERE X and time < (NOW() - INTERVAL 12 HOUR)

you need < rather than > as you want to select records older than 12 hours

Upvotes: 7

Related Questions