note 76450 added to function.gmdate
| From: | code at ashleyhunt dot co dot uk | Date: | Mon, 16 Jul 2007 15:35:21 +0000 |
| Subject: | note 76450 added to function.gmdate | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-128617@lists.php.net to get a copy of this message | ||
Whoops!!
I have just noticed a glitch in my own code submitted a while back, here's the code that works
;-)
<?
function calculate_time_past($start_time, $end_time, $format = "s") {
$time_span = strtotime($end_time) - strtotime($start_time);
if ($format == "s") { // is default format so dynamically calculate date format
if ($time_span > 60) { $format = "i:s"; }
if ($time_span > 3600) { $format = "H:i:s"; }
}
return gmdate($format, $time_span);
}
$start_time = "2007-03-28 00:50:14"; // 00:50:14 will work on its own
$end_time = "2007-03-28 00:52:59"; // 00:52:59 will also work instead
echo calculate_time_past($start_time, $end_time) . "<br />"; // will output 02:45
echo calculate_time_past($start_time, $end_time, "H:i:s"); // will output 00:02:45 when
format is overridden
?>
I hope it of use.
Regards,
Ashley
----
Server IP: 194.145.210.4
Probable Submitter: 217.154.203.18
----
Manual Page -- http://www.php.net/manual/en/function.gmdate.php
Edit -- https://master.php.net/note/edit/76450
Del: integrated -- https://master.php.net/note/delete/76450/integrated
Del: useless -- https://master.php.net/note/delete/76450/useless
Del: bad code -- https://master.php.net/note/delete/76450/bad+code
Del: spam -- https://master.php.net/note/delete/76450/spam
Del: non-english -- https://master.php.net/note/delete/76450/non-english
Del: in docs -- https://master.php.net/note/delete/76450/in+docs
Del: other reasons-- https://master.php.net/note/delete/76450
Reject -- https://master.php.net/note/reject/76450
Search -- https://master.php.net/manage/user-notes.php