note 74374 added to function.time
| From: | spacefish at spacefish dot biz | Date: | Sun, 08 Apr 2007 10:43:18 +0000 |
| Subject: | note 74374 added to function.time | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-125195@lists.php.net to get a copy of this message | ||
if you need to determine the days / hours / minutes / seconds between to timestamp you could use
this function. This is usable if you display time elapsed between last login e.t.c.
/**
* returns duration between two timestamps as an array
* days, hours, minutes, seconds
*
* @param int $start
* @param int $end
* @return array
* @author Timo Witte <spacefish@spacefish.biz>
* @licence GPL
*/
function duration($start, $end) {
// check parameters
if(!is_numeric($start) || !is_numeric($end)) {
user_error("both parameters should be timestamps!");
return false;
}
if($start > $end) {
user_error("don´t begin after you end!");
return false;
}
// difference
$diff = $end-$start;
$ret['days'] = floor($diff/86400);
$diff -= $ret['days']*86400;
$ret['hours'] = floor($diff/3600);
$diff -= $ret['hours']*3600;
$ret['minutes'] = floor($diff/60);
$diff -= $ret['minutes']*60;
$ret['seconds'] = floor($diff);
return $ret;
}
----
Server IP: 217.13.201.10
Probable Submitter: 85.180.41.196 (proxied: unknown)
----
Manual Page -- http://www.php.net/manual/en/function.time.php
Edit -- https://master.php.net/note/edit/74374
Del: integrated -- https://master.php.net/note/delete/74374/integrated
Del: useless -- https://master.php.net/note/delete/74374/useless
Del: bad code -- https://master.php.net/note/delete/74374/bad+code
Del: spam -- https://master.php.net/note/delete/74374/spam
Del: non-english -- https://master.php.net/note/delete/74374/non-english
Del: in docs -- https://master.php.net/note/delete/74374/in+docs
Del: other reasons-- https://master.php.net/note/delete/74374
Reject -- https://master.php.net/note/reject/74374
Search -- https://master.php.net/manage/user-notes.php