note 30015 added to function.date
| From: | Vijay at rack1 dot php dot net | Date: | Tue, 04 Mar 2003 09:22:34 +0000 |
| Subject: | note 30015 added to function.date | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-44816@lists.php.net to get a copy of this message | ||
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.
--
http://www.php.net/manual/en/function.date.php
http://master.php.net/manage/user-notes.php?action=edit+30015
http://master.php.net/manage/user-notes.php?action=delete+30015
http://master.php.net/manage/user-notes.php?action=reject+30015