3v4l.org

run code in 300+ PHP versions simultaneously
<?php function calcDays($startdate, $enddate) { $first = $startdate < $enddate ? $startdate : $enddate; $second = $startdate < $enddate ? $enddate : $startdate; $inbetween = $second - $first; $i[0] = 60; $i[1] = 24; $i[2] = 7; $i[3] = date('t', strtotime('-1 month', $second)); $i[4] = date('L', strtotime('-1 year', $second)) ? 366 : 365; $i[5] = array(31, (date('L', strtotime('-1 year', $second)) ? 28 : 29), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); $days = 0; $temp = floor($inbetween / $i[0] / $i[0] / $i[1]); $tempMonth = date('n', strtotime('-1 year', $second)); for($n = 0; $n < 12; $n++) { $tempMonth = $tempMonth > 10 ? $tempMonth + 1 : 0; var_dump($tempMonth); if($temp >= $i[5][$tempMonth]) { $temp -= $i[5][$tempMonth]; } else { $days = $temp; break; } } $month = floor($inbetween / $i[0] / $i[0] / $i[1] / $i[3] % $i[4]); //$days = floor($inbetween / $i[0] / $i[0] / $i[1] % $i[3]); $hours = floor($inbetween / $i[0] / $i[0] % $i[1]); $minutes = floor($inbetween / $i[0] % $i[0]); $seconds = $inbetween % $i[0]; return $month . " months " . $days . " days " . $hours . " hours " . $minutes . " minutes " . $seconds . " seconds";; } echo calcDays(1388389157, 1419925156);

preferences:
32.66 ms | 402 KiB | 5 Q