CHOOSE WHERE The difference between now and timestamps is less than 24 hours

I want to make a choice of MySQL, where the difference between NOW () and the timestamp in the table is less than a certain period of time, for example 24 hours. I tried doing subtraction, but it did not work, and DateDiff is not what I want. There should be an easy way to do this, but I can't figure it out. Any ideas?

thank

+5
source share
1 answer
SELECT
   timestampdiff(HOUR, yourtimestampcolumn, now() ) as hours_since,
   *
FROM 
   Your_table 
WHERE 
   timestampdiff(HOUR, yourtimestampcolumn, now() ) < 24

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

+1
source

All Articles