note 62129 added to function.mktime

From: Date: Mon, 20 Feb 2006 22:45:06 +0000
Subject: note 62129 added to function.mktime
Groups: php.notes 
Request: Send a blank email to php-notes+get-104091@lists.php.net to get a copy of this message
Sometimes I need to show the difference in hours, minutes and seconds between two events. I calculate the difference with mktime() and date(), which will give me a time in seconds. To show the difference, I use the following function: <?php // Converts seconds in H:M:S function seconds_to_HMS($time_in_secs) { $secs = $time_in_secs % 60; $time_in_secs -= $secs; $time_in_secs /= 60; if ($secs < 10) $secs = "0" . $secs; else $secs = "" . $secs; // force conversion to string $mins = $time_in_secs % 60; $time_in_secs -= $mins; $time_in_secs /= 60; if ($mins < 10) $mins = "0" . $mins; else $mins = "" . $mins; // force conversion to string $hours = $time_in_secs % 60; if($hours < 10) $hours = "0" . $hours; else $hours = "" . $hours; // force conversion to string return $hours . ":" . $mins . ":" . $secs; } ?> There must be some more concise way to do this, but that's what I came up with. ---- Server IP: 200.185.109.101 Probable Submitter: 200.199.251.156 ---- Manual Page -- http://www.php.net/manual/en/function.mktime.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+62129 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+62129&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+62129&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+62129&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+62129&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+62129&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+62129&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+62129&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+62129&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#104091) next »