Calculate Relative Time Ago


/ Published in: SQL
Save to your folder(s)

Here you may find some useful snippets for calculating relative time for different purposes: to get info from a column within certain date, like the latest 7 days, to get time interval etc.


Copy this code and paste it in your HTML
  1. -- Relative time with interval
  2. DATE_SUB(NOW(), INTERVAL 25 HOUR)
  3.  
  4. -- Select all users that were updated in the last 24 hours.
  5. SELECT * FROM users
  6. WHERE users.updated > DATE_SUB(NOW(), INTERVAL 24 HOUR);
  7.  
  8. -- Select all users that were updated in the last 7 days.
  9. SELECT * FROM users
  10. WHERE users.updated > DATE_SUB(NOW(), INTERVAL 7 DAY);

URL: http://www.apphp.com/index.php?snippet=mysql-calculate-relative-time-ago

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.