3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $period = getPeriod('2018-08-21 23:59:59.999999', '2018-08-22 00:00:00.000000'); print_r($period); function getPeriod($date1 = null, $date2 = null) { try { $dt_date1 = new \DateTime($date1); $dt_date2 = new \DateTime($date2); $diff = $dt_date2->diff($dt_date1); // Workaround für PHP Bug #75855 if ($diff->format('%f') < 0) { $diff->s--; //$diff->f++; // = $diff->f + 1; // = number_format($diff->f+1, 6, '.', ''); $diff->f = $diff->f + 1; // = number_format($diff->f+1, 6, '.', ''); } return $diff; } catch (\Exception $e) { $exceptionHanlder = new ExceptionHandler($e); } }
based on PQBrB
Output for 7.2.0 - 7.3.0beta1
DateInterval Object ( [y] => 0 [m] => 0 [d] => 0 [h] => 0 [i] => 0 [s] => 0 [f] => 1.0E-6 [weekday] => 0 [weekday_behavior] => 0 [first_last_day_of] => 0 [invert] => 1 [days] => 0 [special_type] => 0 [special_amount] => 0 [have_weekday_relative] => 0 [have_special_relative] => 0 )
Output for 7.1.0 - 7.1.20
DateInterval Object ( [y] => 0 [m] => 0 [d] => 0 [h] => 0 [i] => 0 [s] => 0 [f] => 1.0000000000288E-6 [weekday] => 0 [weekday_behavior] => 0 [first_last_day_of] => 0 [invert] => 1 [days] => 0 [special_type] => 0 [special_amount] => 0 [have_weekday_relative] => 0 [have_special_relative] => 0 )
Output for 5.3.27 - 5.3.29, 5.4.17 - 5.6.30, 7.0.0 - 7.0.30
DateInterval Object ( [y] => 0 [m] => 0 [d] => 0 [h] => 0 [i] => 0 [s] => 1 [weekday] => 0 [weekday_behavior] => 0 [first_last_day_of] => 0 [invert] => 1 [days] => 0 [special_type] => 0 [special_amount] => 0 [have_weekday_relative] => 0 [have_special_relative] => 0 )
Output for hhvm-3.10.1 - 3.22.0
DateInterval Object ( )
Output for 5.3.0 - 5.3.26, 5.4.0 - 5.4.16
DateInterval Object ( [y] => 0 [m] => 0 [d] => 0 [h] => 0 [i] => 0 [s] => 1 [invert] => 1 [days] => 0 )
Output for 5.2.0 - 5.2.17
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/JJivD on line 9 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/JJivD on line 10 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/JJivD on line 22 Fatal error: Call to undefined method DateTime::diff() in /in/JJivD on line 11
Process exited with code 255.
Output for 5.0.0 - 5.1.6
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/JJivD on line 9 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/JJivD on line 10 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/JJivD on line 22 Fatal error: Class 'DateTime' not found in /in/JJivD on line 9
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected '{' in /in/JJivD on line 8
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected '{' in /in/JJivD on line 8
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/JJivD on line 8
Process exited with code 255.