note 79689 added to function.date
| From: | iffy-inicsoldotcom at osu1 dot php dot net | Date: | Sat, 08 Dec 2007 07:46:04 +0000 |
| Subject: | note 79689 added to function.date | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-132949@lists.php.net to get a copy of this message | ||
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;
}
?>
----
Server IP: 69.147.83.197
Probable Submitter: 203.189.96.3 (proxied: 203.189.101.35)
----
Manual Page -- http://www.php.net/manual/en/function.date.php
Edit -- https://master.php.net/note/edit/79689
Del: integrated -- https://master.php.net/note/delete/79689/integrated
Del: useless -- https://master.php.net/note/delete/79689/useless
Del: bad code -- https://master.php.net/note/delete/79689/bad+code
Del: spam -- https://master.php.net/note/delete/79689/spam
Del: non-english -- https://master.php.net/note/delete/79689/non-english
Del: in docs -- https://master.php.net/note/delete/79689/in+docs
Del: other reasons-- https://master.php.net/note/delete/79689
Reject -- https://master.php.net/note/reject/79689
Search -- https://master.php.net/manage/user-notes.php