Sixem

PHP Time Since Date

Jun 7th, 2013
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.38 KB | None | 0 0
  1. <?php
  2. $eventTime = '2013-06-04 23:23:23';
  3. $age = time() - strtotime($eventTime);
  4. if (60 > $age) {
  5.   echo ($age) . ' Seconds Ago';
  6.   exit;
  7. }
  8. if (3600 > $age) {
  9.   echo round($age / 60, 0) . ' Minutes Ago';
  10.   exit;
  11. }
  12. if (86400 > $age) {
  13.   echo round($age / 3600, 0) . ' Hours Ago';
  14.   exit;
  15. }
  16. if ($age > 86400) {
  17.   echo round($age / 86400, 0) . ' Days Ago';
  18.   exit;
  19. }
  20. ?>
Advertisement
Add Comment
Please, Sign In to add comment