note 102012 deleted from function.time by danbrown

From: Date: Sun, 23 Jan 2011 17:42:36 +0000
Subject: note 102012 deleted from function.time by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-176222@lists.php.net to get a copy of this message
Note Submitter: jessebsmith [at] gmail [dot] com ---- andypsv code can be easily modified to work with future dates as well as past dates. Might not be the best solution, but works for my needs. Change $cur_tm = time(); $dif = $cur_tm-$tm; To $cur_tm = time(); $dif = abs($cur_tm-$tm); Full Code: <?php function _ago($tm,$rcs = 0) { $cur_tm = time(); $dif = abs($cur_tm-$tm); $pds = array('second','minute','hour','day','week','month','year','decade'); $lngh = array(1,60,3600,86400,604800,2630880,31570560,315705600); for($v = sizeof($lngh)-1; ($v >= 0)&&(($no = $dif/$lngh[$v])<=1); $v--); if($v < 0) $v = 0; $_tm = $cur_tm-($dif%$lngh[$v]); $no = floor($no); if($no <> 1) $pds[$v] .='s'; $x=sprintf("%d %s ",$no,$pds[$v]); if(($rcs == 1)&&($v >= 1)&&(($cur_tm-$_tm) > 0)) $x .= time_ago($_tm); return $x; }

« previous php.notes (#176222) next »