3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function datediffInWeeks($date1, $date2) { if($date1 > $date2) return datediffInWeeks($date2, $date1); $first = DateTime::createFromFormat('Y/m/d', $date1); $second = DateTime::createFromFormat('m/d/Y', $date2); return floor($first->diff($second)->days/7); } var_dump(datediffInWeeks('2018-01-01', '2018-02-09'));// 21 var_dump(datediffInWeeks('6/4/2020', '1/2/2021'));// 21
based on Jpga7
Output for 7.3.0alpha1 - 7.3.0beta1
Fatal error: Uncaught Error: Call to a member function diff() on bool in /in/Hpio2:7 Stack trace: #0 /in/Hpio2(10): datediffInWeeks('2018-01-01', '2018-02-09') #1 {main} thrown in /in/Hpio2 on line 7
Process exited with code 255.
Output for 7.0.0 - 7.2.6
Fatal error: Uncaught Error: Call to a member function diff() on boolean in /in/Hpio2:7 Stack trace: #0 /in/Hpio2(10): datediffInWeeks('2018-01-01', '2018-02-09') #1 {main} thrown in /in/Hpio2 on line 7
Process exited with code 255.
Output for hhvm-3.22.0
Fatal error: Uncaught exception 'BadMethodCallException' with message 'Call to a member function diff() on a non-object (boolean)' in /in/Hpio2:-1 Stack trace: #0 /in/Hpio2(-1): datediffInWeeks() #1 {main}
Process exited with code 255.
Output for hhvm-3.18.5 - 3.21.3
Fatal error: Uncaught exception 'BadMethodCallException' with message 'Call to a member function diff() on a non-object (boolean)' in /in/Hpio2:7 Stack trace: #0 /in/Hpio2(10): datediffInWeeks() #1 {main}
Process exited with code 255.
Output for 5.6.0 - 5.6.30
Fatal error: Call to a member function diff() on boolean in /in/Hpio2 on line 7
Process exited with code 255.