Posted By

mattlowden on 09/28/10


Tagged


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

echo419r


time_since


 / Published in: PHP
 

  1. function time_since($original){
  2. $chunks=array(array(60*60*24*365,' year'),array(60*60*24*30,' month'),array(60*60*24*7,' week'),array(60* 60*24,' day'),array(60*60,'hr'),array(60,' min'));
  3. $today=time();
  4. $since=$today-$original;
  5.  
  6. for($i=0,$j=count($chunks);$i<$j;$i++){
  7. $seconds=$chunks[$i][0];
  8. $name=$chunks[$i][1];
  9.  
  10. if(($count=floor($since/$seconds))!=0)break;
  11. }
  12. $print=($count==1)?'1'.$name:"$count{$name}s";
  13. if($i+1<$j){
  14. $seconds2=$chunks[$i+1][0];
  15. $name2=$chunks[$i+1][1];
  16. }
  17. return $print;
  18. }

Report this snippet  

You need to login to post a comment.