note 104918 deleted from function.strtotime by derick
| From: | derick@php.net | Date: | Sun, 03 Nov 2013 15:18:41 +0000 |
| Subject: | note 104918 deleted from function.strtotime by derick | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-197401@lists.php.net to get a copy of this message | ||
Note Submitter: lazzich
----
Calculate the time that past since an event happened:
<?php
function time_ago($date,$time) {
$days = abs(ceil((strtotime($date)-strtotime("now"))/86400));
if ($days > 0) $timepast = $days." days";
if ($days == 1) $timepast = $days." day";
$hours = abs(ceil((strtotime($time)-strtotime("now"))/3600));
if ($days == 0) $timepast = "about ".$hours." hours";
if ($hours == 1) $timepast = "about ".$hours." hour";
$minutes = abs(ceil((strtotime($time)-strtotime("now"))/60))-($hours*60);
if ($hours == 0) $timepast = $minutes." minutes";
if ($minutes == 1) $timepast = $minutes." minute";
return $timepast;
}
$date('2011/07/15');
$time('15:00:00');
echo time_ago($date,$time);
?>