Advertisement
rodro1

time ago function php

Aug 14th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. function timeago($date) {
  2. $timestamp = strtotime($date);
  3.  
  4. $strTime = array("second", "minute", "hour", "day", "month", "year");
  5. $length = array("60","60","24","30","12","10");
  6.  
  7. $currentTime = time();
  8. if($currentTime >= $timestamp) {
  9. $diff = time()- $timestamp;
  10. for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) {
  11. $diff = $diff / $length[$i];
  12. }
  13.  
  14. $diff = round($diff);
  15. return $diff . " " . $strTime[$i] . "(s) ago ";
  16. }
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement