Posted By

Jamie on 06/16/12


Tagged

time relative


Versions (?)

MySQL Time Ago function


 / Published in: MySQL
 

Retrieves a relative time in a MySQL Query

  1. # Relative Time
  2. DATE_SUB( NOW( ) , INTERVAL 25 HOUR )
  3.  
  4. # For example:
  5. # Select all users who were updated in the last 25 hours.
  6. SELECT * FROM users
  7. WHERE users.updated > DATE_SUB( NOW( ) , INTERVAL 25 HOUR );
  8.  
  9. # Select all users who were updated in the last 2 days.
  10. SELECT * FROM users
  11. WHERE users.updated > DATE_SUB( NOW( ) , INTERVAL 2 DAY );

Report this snippet  

You need to login to post a comment.