note 102012 added to function.time
| From: | jessebsmith | Date: | Sun, 23 Jan 2011 00:41:54 +0000 |
| Subject: | note 102012 added to function.time | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-176016@lists.php.net to get a copy of this message | ||
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;
}
----
Server IP: 69.147.83.197
Probable Submitter: 96.38.162.177
----
Manual Page -- http://www.php.net/manual/en/function.time.php
Edit -- https://master.php.net/note/edit/102012
Del: integrated -- https://master.php.net/note/delete/102012/integrated
Del: useless -- https://master.php.net/note/delete/102012/useless
Del: bad code -- https://master.php.net/note/delete/102012/bad+code
Del: spam -- https://master.php.net/note/delete/102012/spam
Del: non-english -- https://master.php.net/note/delete/102012/non-english
Del: in docs -- https://master.php.net/note/delete/102012/in+docs
Del: other reasons-- https://master.php.net/note/delete/102012
Reject -- https://master.php.net/note/reject/102012
Search -- https://master.php.net/manage/user-notes.php