note 62129 deleted from function.mktime by bjori

From: Date: Thu, 01 Jun 2006 18:37:01 +0000
Subject: note 62129 deleted from function.mktime by bjori
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-112803@lists.php.net to get a copy of this message
Note Submitter: espinafre at gmail dot com ---- 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.

« previous php.notes (#112803) next »