note 68037 deleted from ref.datetime by danbrown
| From: | danbrown@php.net | Date: | Wed, 20 May 2009 02:46:11 +0000 |
| Subject: | note 68037 deleted from ref.datetime by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-155775@lists.php.net to get a copy of this message | ||
Note Submitter: cepercival at thatMailThatsHot dot com
----
Hopefully this may be useful to someone out there!
I wanted a simple function to give me a duration for phone calls using a start timestamp and end
timestamp. After finding an understandable example here http://www.brenlei.com/articles/php/dates/dates4.php
i cobbled this together:
<?php
function callDuration($dateTimeBegin,$dateTimeEnd) {
$dif=$dateTimeEnd - $dateTimeBegin;
$hours = floor($dif / 3600);
$temp_remainder = $dif - ($hours * 3600);
$minutes = floor($temp_remainder / 60);
$temp_remainder = $temp_remainder - ($minutes * 60);
$seconds = $temp_remainder;
// leading zero's - not bothered about hours
$min_lead=':';
if($minutes <=9)
$min_lead .= '0';
$sec_lead=':';
if($seconds <=9)
$sec_lead .= '0';
// difference/duration returned as Hours:Mins:Secs e.g. 01:29:32
return $hours.$min_lead.$minutes.$sec_lead.$seconds;
}
?>
obviously it can be easily extended to include days, weeks etc.
Stupidly simple I know but that's how i like it.