note 61259 added to function.mktime
| From: | (staffatbibivudotcom) | Date: | Sun, 29 Jan 2006 18:29:34 +0000 |
| Subject: | note 61259 added to function.mktime | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-102677@lists.php.net to get a copy of this message | ||
here a function that will help to find the difference between two dates, and it will take into
consideration the leaps years
this function will return an array with:
YEARS (years)
MONTHS (months)
DAYS (days)
HOURS (hours)
MINUTES (minutes)
SECONDS (seconds)
probably can be optimized, but for now does the work
--------------------------------------------------------
Una funzione che aiuta a trovare la differenze tra due date, prendendo in considerazione anche gli
anni bisestili.
Questa funzione ritorna un array con:
ANNI (years)
MESI (months)
GIORNI (days)
ORE (hours)
MINUTI (minutes)
SECONDI (seconds)
probabilmente puo' essere ottimizzata, ma per ora funziona
----------------------------------------------------------
<?php
function bib_datediff($fromtime, $totime=''){
if($totime=='') $totime = time();
if($fromtime>$totime){
$tmp = $totime;
$totime = $fromtime;
$fromtime = $tmp;
}
$timediff = $totime-$fromtime;
//check for leap years in the middle
for($i=date('Y',$fromtime); $i<=date('Y',$totime); $i++){
if ((($i%4 == 0) && ($i%100 != 0)) || ($i%400 == 0)) {
$timediff -= 24*60*60;
}
}
$remain = $timediff;
$ret['years'] = intval($remain/(365*24*60*60));
$remain = $remain%(365*24*60*60);
$ret['days'] = intval($remain/(24*60*60));
$remain = $remain%(24*60*60);
$m[0] = 31; $m[1] = 28; $m[2] = 31; $m[3] = 30;
$m[4] = 31; $m[5] = 30; $m[6] = 31; $m[7] = 31;
$m[8] = 30; $m[9] = 31; $m[10] = 30; $m[11] = 31;
//if leap year, february has 29 days
if (((date('Y',$totime)%4 == 0) && (date('Y',$totime)%100 != 0)) ||
(date('Y',$totime)%400 == 0)){
$m[1] = 29;
}
$ret['months'] = 0;
foreach($m as $value){
if($ret['days']>$value){
$ret['months']++;
$ret['days'] -=$value;
} else {
break;
}
}
$ret['hours'] = intval($remain/(60*60));
$remain = $remain%(60*60);
$ret['minutes'] = intval($remain/60);
$ret['seconds'] = $remain%60;
return $ret;
}
?>
----
Server IP: 216.194.113.175
Probable Submitter: 65.184.175.29
----
Manual Page -- http://www.php.net/manual/en/function.mktime.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+61259
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+61259&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+61259&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+61259&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+61259&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+61259&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+61259&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+61259&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+61259&report=yes
Search -- http://master.php.net/manage/user-notes.php