note 76451 deleted from function.gmdate by nlopess

From: Date: Mon, 16 Jul 2007 18:02:47 +0000
Subject: note 76451 deleted from function.gmdate by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-128626@lists.php.net to get a copy of this message
Note Submitter: code at ashleyhunt dot co dot uk ---- 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

« previous php.notes (#128626) next »