@ 2013-12-30T11:38:35Z <?php
function dateDiff($startdate, $enddate) {
$first = $startdate < $enddate ? $startdate : $enddate;
$second = $startdate < $enddate ? $enddate : $startdate;
$inbetween = $second - $first;
$i[0] = 60;
$i[1] = 24;
$i[2] = array(31, (date('L', strtotime('-1 year', $second)) ? 28 : 29), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
$months = 0;
$days = 0;
$tempDays = $inbetween / $i[0] / $i[0] / $i[1] / 365.25;
var_dump($tempDays);
$tempMonth = date('n', strtotime('-1 year', $second)) - 1;
for($n = 0; $n < 12; $n++) {
if($tempDays >= $i[2][$tempMonth]) {
$months += 1;
$tempDays -= $i[2][$tempMonth];
} else {
$days = floor($tempDays);
break;
}
$tempMonth = $tempMonth < 10 ? $tempMonth + 1 : 0;
}
$years = floor(date('Y', $second) - date('Y', $first) + $months / 12);
$months = $months % 12;
$hours = floor($inbetween / $i[0] / $i[0] % $i[1]);
$minutes = floor($inbetween / $i[0] % $i[0]);
$seconds = $inbetween % $i[0];
$dateObj = new stdClass();
$dateObj->years = $years;
$dateObj->months = $months;
$dateObj->days = $days;
$dateObj->hours = $hours;
$dateObj->minutes = $minutes;
$dateObj->seconds = $seconds;
return $dateObj;
}
$mydate = dateDiff(1388534400, 51417392000);
echo $mydate->years, " years, ", $mydate->months, " months, ", $mydate->days, " days, ", $mydate->hours, " hours, ", $mydate->minutes, " minutes, and ", $mydate->seconds, " seconds";
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for 8.1.0 - 8.1.31 , 8.2.0 - 8.2.26 , 8.3.0 - 8.3.14 , 8.4.1 - 8.4.2 float(1585.3188328643496)
Deprecated: Implicit conversion from float 13896904.88888889 to int loses precision in /in/unoct on line 34
Deprecated: Implicit conversion from float 833814293.3333334 to int loses precision in /in/unoct on line 35
1586 years, 0 months, 0 days, 16 hours, 53 minutes, and 20 seconds Output for 8.0.0 - 8.0.30 float(1585.3188328643496)
1586 years, 0 months, 0 days, 16 hours, 53 minutes, and 20 seconds Output for 4.3.0 - 4.3.11 , 4.4.0 - 4.4.9 , 5.0.0 - 5.0.5 , 5.1.0 - 5.1.6 , 5.2.0 - 5.2.17 , 5.3.0 - 5.3.29 , 5.4.0 - 5.4.45 , 5.5.0 - 5.5.37 , 5.6.0 - 5.6.28 , 7.0.0 - 7.0.20 , 7.1.0 - 7.1.33 , 7.2.0 - 7.2.33 , 7.3.0 - 7.3.33 , 7.4.0 - 7.4.33 float(1585.3188328643)
1586 years, 0 months, 0 days, 16 hours, 53 minutes, and 20 seconds preferences:dark mode live preview
49.83 ms | 411 KiB | 5 Q