note 50656 added to function.time

From: Date: Sun, 06 Mar 2005 04:52:54 +0000
Subject: note 50656 added to function.time
Groups: php.notes 
Request: Send a blank email to php-notes+get-85987@lists.php.net to get a copy of this message
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. ---- Manual Page -- http://www.php.net/manual/en/function.time.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+50656 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+50656&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+50656&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+50656&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+50656&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+50656&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+50656&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#85987) next »