Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

select timestamp older than

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

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

Type : timestamp

You're right Salman A .Thanks

like image 799
Xtal Avatar asked May 29 '12 13:05

Xtal


1 Answers

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

like image 140
Manse Avatar answered Sep 20 '22 01:09

Manse