note 82260 deleted from function.time by aidan
| From: | aidan@php.net | Date: | Wed, 15 Apr 2009 16:05:23 +0000 |
| Subject: | note 82260 deleted from function.time by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-153332@lists.php.net to get a copy of this message | ||
Note Submitter: binupillai2003 at yahoo dot com
----
Calculate time difference(24 hours system)
<?php
//Author Binu.v.Pillai
function diffTime($bigTime,$smallTime)
{
//input format hh:mm:ss
list($h1,$m1,$s1)=split(":",$bigTime);
list($h2,$m2,$s2)=split(":",$smallTime);
$second1=$s1+($h1*3600)+($m1*60);//converting it into seconds
$second2=$s2+($h2*3600)+($m2*60);
if ($second1==$second2)
{
$resultTime="00:00:00";
return $resultTime;
exit();
}
if ($second1<$second2) //
{
$second1=$second1+(24*60*60);//adding 24 hours to it.
}
$second3=$second1-$second2;
//print $second3;
if ($second3==0)
{
$h3=0;
}
else
{
$h3=floor($second3/3600);//find total hours
}
$remSecond=$second3-($h3*3600);//get remaining seconds
if ($remSecond==0)
{
$m3=0;
}
else
{
$m3=floor($remSecond/60);// for finding remaining minutes
}
$s3=$remSecond-(60*$m3);
if($h3==0)//formating result.
{
$h3="00";
}
if($m3==0)
{
$m3="00";
}
if($s3==0)
{
$s3="00";
}
$resultTime="$h3:$m3:$s3";
return $resultTime;
}
?>