note 30015 deleted from function.date by sniper
| From: | sniper@php.net | Date: | Sat, 11 Oct 2003 16:53:09 +0000 |
| Subject: | note 30015 deleted from function.date by sniper | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-58282@lists.php.net to get a copy of this message | ||
Note Submitter: Vijay K. Chikte
----
As there is no function to calculate the time difference between the two times/dates, I used the
following function to calculate the difference.
function unixTm($strDT)
{
$arrDT = explode(" ", $strDT);
$arrD = explode("-", $arrDT[0]);
$arrT = explode(":", $arrDT[1]);
return mktime($arrT[0], $arrT[1], $arrT[2], $arrD[1], $arrD[2], $arrD[0]);
}
function dateDiff ($date1,$date2)
{
$dt2=unixTm($date2) ;
$dt1=unixTm($date1) ;
$r = $dt2 - $dt1;
$dd=floor($r / 86400) ;
if ($dd<=9) $dd="0".$dd ;
$r=$r % 86400 ;
$hh=floor($r/3600) ;
if ($hh<=9) $hh="0".$hh ;
$r=$r % 3600 ;
$mm=floor($r/60) ;
if ($mm<=9) $mm="0".$mm ;
$r=$r % 60 ;
$ss=$r ;
if ($ss<=9) $ss="0".$ss ;
$retval="$hh:$mm:$ss" ;
return $retval;
}
Hope this helps.