note 79689 deleted from function.date by derick
| From: | derick@php.net | Date: | Sun, 09 Dec 2007 13:36:11 +0000 |
| Subject: | note 79689 deleted from function.date by derick | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-132994@lists.php.net to get a copy of this message | ||
Note Submitter: iffy - inicsol dot com
----
This function could be used to get the difference between two dates up to years and seconds
<?
function time_difference($stime, $etime){
$years=$months=$days=$hours=$mins=$secs=0;
$starttime = strtotime($stime);
// the start time can change to =strtotime($endtime);
$endtime = strtotime($etime);
//$endtime can be any format as well as it can be converted to secs
$timediff = $endtime-$starttime;
if(floor(($timediff/31536000)) >0){ //Check for Years greater than 0
$years = floor(($timediff/31536000));
}else{
$years= 0;
if(floor(($timediff/2628000)) >0){ //check for Months greater than 0
$months = floor(($timediff/2628000));
if($months >12){
$months = $months-12;
}
}else{
$months = 0;
$days=intval($timediff/86400);
$remain=$timediff%86400;
$hours=intval($remain/3600);
$remain=$remain%3600;
$mins=intval($remain/60);
$secs=$remain%60;
}
}
//couple of lines of the code are copied from the other note!thx to that guy!
$timediff= array("years"=>$years, "months"=>$months,
"days"=>$days, "hours"=>$hours, "mins"=>$mins,
"secs"=>$secs);
return $timediff;
}
?>