note 77182 deleted from ref.datetime by nlopess
| From: | nlopess@php.net | Date: | Sat, 01 Sep 2007 11:58:14 +0000 |
| Subject: | note 77182 deleted from ref.datetime by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-129995@lists.php.net to get a copy of this message | ||
Note Submitter: Sam Yong - hellclanner [at] live dot com
----
I wanted to do something like "10 days 2 months 5 years ago" so i came up with this
following function to help me get an array of the "ago" time.
<?php
function timeAgo($tzSince){
$years = floor($tzSince/(60*60*24*365));
if($years>=0){$tzSince = $tzSince - ($year*60*60*24*365);}
$mths = floor($tzSince/(60*60*24*30));
if($mths>=0){$tzSince = $tzSince - ($mths*60*60*24*30);}
$days = floor($tzSince/(60*60*24));
if($days>0){$tzSince = $tzSince - ($days*60*60*24);}
$hours = floor($tzSince/(60*60));
if($hours>0){$tzSince = $tzSince - ($hours*60*60);}
$minutes= floor($tzSince/(60));
if($minutes>0){$tzSince = $tzSince - ($minutes*60);}
$sec= floor($tzSince);
$Arr_Since = array(
'years' => $years,
'months' => $mths,
'days' => $days,
'hours' => $hours,
'minutes' => $minutes,
'seconds' => $sec
);
return $Arr_Since;
}
?>
Used successfully in http://betapod.hellclanner.com/