note 74374 deleted from function.time by bjori

From: Date: Sun, 08 Apr 2007 16:21:03 +0000
Subject: note 74374 deleted from function.time by bjori
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-125220@lists.php.net to get a copy of this message
Note Submitter: spacefish at spacefish dot biz Reason: bad code ---- 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; }

« previous php.notes (#125220) next »