3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function getDateDifference($dateFrom, $dateTo, $unit = 'd') { $difference = null; $dateFromElements = split(' ', $dateFrom); $dateToElements = split(' ', $dateTo); $dateFromDateElements = split('-', $dateFromElements[0]); $dateFromTimeElements = split(':', $dateFromElements[1]); $dateToDateElements = split('-', $dateToElements[0]); $dateToTimeElements = split(':', $dateToElements[1]); // Get unix timestamp for both dates $dateFromTimeElements[0] = ($dateFromTimeElements[0] == '') ? 0 : $dateFromTimeElements[0]; $dateFromTimeElements[1] = ($dateFromTimeElements[1] == '') ? 0 : $dateFromTimeElements[1]; $dateFromTimeElements[2] = ($dateFromTimeElements[2] == '') ? 0 : $dateFromTimeElements[2]; $date1 = mktime($dateFromTimeElements[0], $dateFromTimeElements[1], $dateFromTimeElements[2], $dateFromDateElements[1], $dateFromDateElements[2], $dateFromDateElements[0]); $dateToTimeElements[0] = ($dateToTimeElements[0] == '') ? 0 : $dateToTimeElements[0]; $dateToTimeElements[1] = ($dateToTimeElements[1] == '') ? 0 : $dateToTimeElements[1]; $dateToTimeElements[2] = ($dateToTimeElements[2] == '') ? 0 : $dateToTimeElements[2]; $date2 = mktime($dateToTimeElements[0], $dateToTimeElements[1], $dateToTimeElements[2], $dateToDateElements[1], $dateToDateElements[2], $dateToDateElements[0]); if ($date1 > $date2) { return null; } $diff = $date2 - $date1; $days = 0; $hours = 0; $minutes = 0; $seconds = 0; if ($diff % 86400 <= 0) { // there are 86,400 seconds in a day $days = $diff / 86400; } if ($diff % 86400 > 0) { $rest = ($diff % 86400); $days = ($diff - $rest) / 86400; if ($rest % 3600 > 0) { $rest1 = ($rest % 3600); $hours = ($rest - $rest1) / 3600; if ($rest1 % 60 > 0) { $rest2 = ($rest1 % 60); $minutes = ($rest1 - $rest2) / 60; $seconds = $rest2; } else { $minutes = $rest1 / 60; } } else { $hours = $rest / 3600; } } switch ($unit) { case 'd': case 'D': $partialDays = 0; $partialDays += ($seconds / 86400); $partialDays += ($minutes / 1440); $partialDays += ($hours / 24); $difference = $days + $partialDays; break; case 'h': case 'H': $partialHours = 0; $partialHours += ($seconds / 3600); $partialHours += ($minutes / 60); $difference = $hours + ($days * 24) + $partialHours; break; case 'm': case 'M': $partialMinutes = 0; $partialMinutes += ($seconds / 60); $difference = $minutes + ($days * 1440) + ($hours * 60) + $partialMinutes; break; case 's': case 'S': $difference = $seconds + ($days * 86400) + ($hours * 3600) + ($minutes * 60); break; case 'a': case 'A': $difference = array( "days" => $days, "hours" => $hours, "minutes" => $minutes, "seconds" => $seconds ); break; } return $difference; } echo getDateDifference("2014-03-31","2010-05-16");
Output for 7.0.0 - 7.1.0
Fatal error: Uncaught Error: Call to undefined function split() in /in/oL5SL:6 Stack trace: #0 /in/oL5SL(94): getDateDifference('2014-03-31', '2010-05-16') #1 {main} thrown in /in/oL5SL on line 6
Process exited with code 255.
Output for hhvm-3.12.0
Notice: Undefined index: 1 in /in/oL5SL on line 9 Warning: split() expects parameter 2 to be string, null given in /in/oL5SL on line 9 Notice: Undefined index: 1 in /in/oL5SL on line 11 Warning: split() expects parameter 2 to be string, null given in /in/oL5SL on line 11 Notice: Undefined index: 1 in /in/oL5SL on line 15 Notice: Undefined index: 2 in /in/oL5SL on line 16 Notice: Undefined index: 1 in /in/oL5SL on line 21 Notice: Undefined index: 2 in /in/oL5SL on line 22
Output for hhvm-3.10.0
Notice: Undefined index: 1 in /in/oL5SL on line 9 Notice: Undefined index: 1 in /in/oL5SL on line 11 Notice: Undefined index: 1 in /in/oL5SL on line 15 Notice: Undefined index: 2 in /in/oL5SL on line 16 Notice: Undefined index: 1 in /in/oL5SL on line 21 Notice: Undefined index: 2 in /in/oL5SL on line 22
Output for 5.3.0 - 5.6.28
Deprecated: Function split() is deprecated in /in/oL5SL on line 6 Deprecated: Function split() is deprecated in /in/oL5SL on line 7 Deprecated: Function split() is deprecated in /in/oL5SL on line 8 Notice: Undefined offset: 1 in /in/oL5SL on line 9 Deprecated: Function split() is deprecated in /in/oL5SL on line 9 Deprecated: Function split() is deprecated in /in/oL5SL on line 10 Notice: Undefined offset: 1 in /in/oL5SL on line 11 Deprecated: Function split() is deprecated in /in/oL5SL on line 11 Notice: Undefined offset: 1 in /in/oL5SL on line 15 Notice: Undefined offset: 2 in /in/oL5SL on line 16 Notice: Undefined offset: 1 in /in/oL5SL on line 21 Notice: Undefined offset: 2 in /in/oL5SL on line 22
Output for 4.3.0 - 5.2.17
Notice: Undefined offset: 1 in /in/oL5SL on line 9 Notice: Undefined offset: 1 in /in/oL5SL on line 11 Notice: Undefined offset: 1 in /in/oL5SL on line 15 Notice: Undefined offset: 2 in /in/oL5SL on line 16 Notice: Undefined offset: 1 in /in/oL5SL on line 21 Notice: Undefined offset: 2 in /in/oL5SL on line 22