note 50656 deleted from function.time by aidan

From: Date: Sat, 08 Oct 2005 01:03:48 +0000
Subject: note 50656 deleted from function.time by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-96610@lists.php.net to get a copy of this message
Note Submitter: webmaster at com1net dot com ---- Here's an updated function which adds the months and weeks. . . function calcElapsedTime($time) { // calculate elapsed time (in seconds!) $diff = time()-$time; $yearsDiff = floor($diff/60/60/24/365); $diff -= $yearsDiff*60*60*24*365; $monthsDiff = floor($diff/60/60/24/30); $diff -= $monthsDiff*60*60*24*30; $weeksDiff = floor($diff/60/60/24/7); $diff -= $weeksDiff*60*60*24*7; $daysDiff = floor($diff/60/60/24); $diff -= $daysDiff*60*60*24; $hrsDiff = floor($diff/60/60); $diff -= $hrsDiff*60*60; $minsDiff = floor($diff/60); $diff -= $minsDiff*60; $secsDiff = $diff; return (''.$yearsDiff.' year'.(($yearsDiff <> 1) ? "s" : "").', '.$monthsDiff.' month'.(($monthsDiff <> 1) ? "s" : "").', '.$weeksDiff.' week'.(($weeksDiff <> 1) ? "s" : "").', '.$daysDiff.' day'.(($daysDiff <> 1) ? "s" : "").', '.$hrsDiff.' hour'.(($hrsDiff <> 1) ? "s" : "").', '.$minsDiff.' minute'.(($minsDiff <> 1) ? "s" : "").', '.$secsDiff.' second'.(($secsDiff <> 1) ? "s" : "").''); } Call with: $last = calcElapsedTime(mktime(0, 0, 0, 6, 20, 2000)); echo "Online: ".$last.".<br>"; Output: Online: 4 years, 8 months, 2 weeks, 1 day, 21 hours, 1 minute, 29 seconds.

« previous php.notes (#96610) next »