3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $dateFrom="2014-03-31"; $dateTo="2014-05-16"; { $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; } echo $difference; }
Output for 7.0.0 - 7.1.0
Fatal error: Uncaught Error: Call to undefined function split() in /in/079dv:9 Stack trace: #0 {main} thrown in /in/079dv on line 9
Process exited with code 255.
Output for 5.3.0 - 5.6.28
Deprecated: Function split() is deprecated in /in/079dv on line 9 Deprecated: Function split() is deprecated in /in/079dv on line 10 Deprecated: Function split() is deprecated in /in/079dv on line 11 Notice: Undefined offset: 1 in /in/079dv on line 12 Deprecated: Function split() is deprecated in /in/079dv on line 12 Deprecated: Function split() is deprecated in /in/079dv on line 13 Notice: Undefined offset: 1 in /in/079dv on line 14 Deprecated: Function split() is deprecated in /in/079dv on line 14 Notice: Undefined offset: 1 in /in/079dv on line 18 Notice: Undefined offset: 2 in /in/079dv on line 19 Notice: Undefined offset: 1 in /in/079dv on line 24 Notice: Undefined offset: 2 in /in/079dv on line 25 Notice: Undefined variable: unit in /in/079dv on line 59 Notice: Undefined variable: unit in /in/079dv on line 60 Notice: Undefined variable: unit in /in/079dv on line 67 Notice: Undefined variable: unit in /in/079dv on line 68 Notice: Undefined variable: unit in /in/079dv on line 74 Notice: Undefined variable: unit in /in/079dv on line 75 Notice: Undefined variable: unit in /in/079dv on line 80 Notice: Undefined variable: unit in /in/079dv on line 81 Notice: Undefined variable: unit in /in/079dv on line 84 Notice: Undefined variable: unit in /in/079dv on line 85
Output for 5.1.0 - 5.2.17
Notice: Undefined offset: 1 in /in/079dv on line 12 Notice: Undefined offset: 1 in /in/079dv on line 14 Notice: Undefined offset: 1 in /in/079dv on line 18 Notice: Undefined offset: 2 in /in/079dv on line 19 Notice: Undefined offset: 1 in /in/079dv on line 24 Notice: Undefined offset: 2 in /in/079dv on line 25 Notice: Undefined variable: unit in /in/079dv on line 59 Notice: Undefined variable: unit in /in/079dv on line 60 Notice: Undefined variable: unit in /in/079dv on line 67 Notice: Undefined variable: unit in /in/079dv on line 68 Notice: Undefined variable: unit in /in/079dv on line 74 Notice: Undefined variable: unit in /in/079dv on line 75 Notice: Undefined variable: unit in /in/079dv on line 80 Notice: Undefined variable: unit in /in/079dv on line 81 Notice: Undefined variable: unit in /in/079dv on line 84 Notice: Undefined variable: unit in /in/079dv on line 85
Output for 5.0.4 - 5.0.5
Notice: Undefined offset: 1 in /in/079dv on line 12 Notice: Undefined offset: 1 in /in/079dv on line 14 Notice: Undefined offset: 1 in /in/079dv on line 18 Notice: Undefined offset: 2 in /in/079dv on line 19 Notice: Undefined offset: 1 in /in/079dv on line 24 Notice: Undefined offset: 2 in /in/079dv on line 25 Notice: Undefined variable: unit in /in/079dv on line 58
Output for 4.3.0 - 5.0.3
Notice: Undefined offset: 1 in /in/079dv on line 12 Notice: Undefined offset: 1 in /in/079dv on line 14 Notice: Undefined offset: 1 in /in/079dv on line 18 Notice: Undefined offset: 2 in /in/079dv on line 19 Notice: Undefined offset: 1 in /in/079dv on line 24 Notice: Undefined offset: 2 in /in/079dv on line 25 Notice: Undefined variable: unit in /in/079dv on line 58