Advertisement
Guest User

Untitled

a guest
Jul 27th, 2011
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.44 KB | None | 0 0
  1. function ago($timestamp)
  2. {
  3.     $difference = time() - $timestamp;
  4.    
  5.     $periods = array("second", "minute", "hour", "day", "week", "month", "years", "decade");
  6.     $lengths = array("60","60","24","7","4.35","12","10");
  7.     for($j = 0; $difference >= $lengths[$j]; $j++)
  8.     {
  9.         $difference /= $lengths[$j];
  10.     }
  11.    
  12.     $difference = round($difference);
  13.     if($difference != 1) $periods[$j].= "s";
  14.    
  15.     $text = "$difference $periods[$j] ago";
  16.     return $text;
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement