note 68037 added to ref.datetime
| From: | cepercival at thatMailThatsHot dot com | Date: | Tue, 11 Jul 2006 12:31:55 +0000 |
| Subject: | note 68037 added to ref.datetime | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-114665@lists.php.net to get a copy of this message | ||
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:
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.
----
Server IP: 83.138.144.80
Probable Submitter: 213.160.100.186
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/ref.datetime.php
Edit -- http://master.php.net/note/edit/68037
Del: integrated -- http://master.php.net/note/delete/68037/integrated
Del: useless -- http://master.php.net/note/delete/68037/useless
Del: bad code -- http://master.php.net/note/delete/68037/bad+code
Del: spam -- http://master.php.net/note/delete/68037/spam
Del: non-english -- http://master.php.net/note/delete/68037/non-english
Del: in docs -- http://master.php.net/note/delete/68037/in+docs
Del: other reasons-- http://master.php.net/note/delete/68037
Reject -- http://master.php.net/note/reject/68037
Search -- http://master.php.net/manage/user-notes.php