Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SELECT WHERE difference between now and a timestamp is less than 24 hours

I want to make a MySQL selection where the difference between NOW() and a timestamp in the table is less than a specific period of time, like 24 hours. I've tried doing subtraction but it hasn't worked and DateDiff isn't what I want. There must be a simple way to do this, but I can't figure it out. Any ideas?

Thanks

like image 702
george Avatar asked Oct 22 '22 13:10

george


1 Answers

SELECT
   timestampdiff(HOUR, yourtimestampcolumn, now() ) as hours_since,
   *
FROM 
   Your_table 
WHERE 
   timestampdiff(HOUR, yourtimestampcolumn, now() ) < 24

Refer https://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_timestampdiff

like image 177
Sepster Avatar answered Oct 24 '22 05:10

Sepster