3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?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);
Output for 5.3.0 - 5.6.28, 7.0.0 - 7.1.0
int(13) Notice: Undefined offset: 13 in /in/ZL52i on line 24 Notice: Undefined offset: 13 in /in/ZL52i on line 25 int(14) Notice: Undefined offset: 14 in /in/ZL52i on line 24 Notice: Undefined offset: 14 in /in/ZL52i on line 25 int(15) Notice: Undefined offset: 15 in /in/ZL52i on line 24 Notice: Undefined offset: 15 in /in/ZL52i on line 25 int(16) Notice: Undefined offset: 16 in /in/ZL52i on line 24 Notice: Undefined offset: 16 in /in/ZL52i on line 25 int(17) Notice: Undefined offset: 17 in /in/ZL52i on line 24 Notice: Undefined offset: 17 in /in/ZL52i on line 25 int(18) Notice: Undefined offset: 18 in /in/ZL52i on line 24 Notice: Undefined offset: 18 in /in/ZL52i on line 25 int(19) Notice: Undefined offset: 19 in /in/ZL52i on line 24 Notice: Undefined offset: 19 in /in/ZL52i on line 25 int(20) Notice: Undefined offset: 20 in /in/ZL52i on line 24 Notice: Undefined offset: 20 in /in/ZL52i on line 25 int(21) Notice: Undefined offset: 21 in /in/ZL52i on line 24 Notice: Undefined offset: 21 in /in/ZL52i on line 25 int(22) Notice: Undefined offset: 22 in /in/ZL52i on line 24 Notice: Undefined offset: 22 in /in/ZL52i on line 25 int(23) Notice: Undefined offset: 23 in /in/ZL52i on line 24 Notice: Undefined offset: 23 in /in/ZL52i on line 25 int(24) Notice: Undefined offset: 24 in /in/ZL52i on line 24 Notice: Undefined offset: 24 in /in/ZL52i on line 25 12 months 0 days 23 hours 59 minutes 59 seconds
Output for hhvm-3.10.0 - 3.12.0
int(13) Notice: Undefined index: 13 in /in/ZL52i on line 24 Notice: Undefined index: 13 in /in/ZL52i on line 25 int(14) Notice: Undefined index: 14 in /in/ZL52i on line 24 Notice: Undefined index: 14 in /in/ZL52i on line 25 int(15) Notice: Undefined index: 15 in /in/ZL52i on line 24 Notice: Undefined index: 15 in /in/ZL52i on line 25 int(16) Notice: Undefined index: 16 in /in/ZL52i on line 24 Notice: Undefined index: 16 in /in/ZL52i on line 25 int(17) Notice: Undefined index: 17 in /in/ZL52i on line 24 Notice: Undefined index: 17 in /in/ZL52i on line 25 int(18) Notice: Undefined index: 18 in /in/ZL52i on line 24 Notice: Undefined index: 18 in /in/ZL52i on line 25 int(19) Notice: Undefined index: 19 in /in/ZL52i on line 24 Notice: Undefined index: 19 in /in/ZL52i on line 25 int(20) Notice: Undefined index: 20 in /in/ZL52i on line 24 Notice: Undefined index: 20 in /in/ZL52i on line 25 int(21) int(22) int(23) int(24) 12 months 0 days 23 hours 59 minutes 59 seconds
Output for 4.3.0 - 5.2.17
int(13) Notice: Undefined offset: 13 in /in/ZL52i on line 24 Notice: Undefined offset: 13 in /in/ZL52i on line 25 int(14) Notice: Undefined offset: 14 in /in/ZL52i on line 24 Notice: Undefined offset: 14 in /in/ZL52i on line 25 int(15) Notice: Undefined offset: 15 in /in/ZL52i on line 24 Notice: Undefined offset: 15 in /in/ZL52i on line 25 int(16) Notice: Undefined offset: 16 in /in/ZL52i on line 24 Notice: Undefined offset: 16 in /in/ZL52i on line 25 int(17) Notice: Undefined offset: 17 in /in/ZL52i on line 24 Notice: Undefined offset: 17 in /in/ZL52i on line 25 int(18) Notice: Undefined offset: 18 in /in/ZL52i on line 24 Notice: Undefined offset: 18 in /in/ZL52i on line 25 int(19) Notice: Undefined offset: 19 in /in/ZL52i on line 24 Notice: Undefined offset: 19 in /in/ZL52i on line 25 int(20) Notice: Undefined offset: 20 in /in/ZL52i on line 24 Notice: Undefined offset: 20 in /in/ZL52i on line 25 int(21) Notice: Undefined offset: 21 in /in/ZL52i on line 24 Notice: Undefined offset: 21 in /in/ZL52i on line 25 int(22) Notice: Undefined offset: 22 in /in/ZL52i on line 24 Notice: Undefined offset: 22 in /in/ZL52i on line 25 int(23) Notice: Undefined offset: 23 in /in/ZL52i on line 24 Notice: Undefined offset: 23 in /in/ZL52i on line 25 int(24) Notice: Undefined offset: 24 in /in/ZL52i on line 24 Notice: Undefined offset: 24 in /in/ZL52i on line 25 12 months 0 days 23 hours 59 minutes 59 seconds