3v4l.org

run code in 300+ PHP versions simultaneously
<?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
Output for git.master, git.master_jit
Fatal error: Uncaught TypeError: DateTime::diff(): Argument #1 ($targetObject) must be of type DateTimeInterface, bool given in /in/Jpga7:7 Stack trace: #0 /in/Jpga7(7): DateTime->diff(false) #1 /in/Jpga7(10): datediffInWeeks('2018-01-01', '2018-02-09') #2 {main} thrown in /in/Jpga7 on line 7
Process exited with code 255.
Output for rfc.property-hooks
Fatal error: Uncaught TypeError: DateTime::diff(): Argument #1 ($targetObject) must be of type DateTimeInterface, false given in /in/Jpga7:7 Stack trace: #0 /in/Jpga7(7): DateTime->diff(false) #1 /in/Jpga7(10): datediffInWeeks('2018-01-01', '2018-02-09') #2 {main} thrown in /in/Jpga7 on line 7
Process exited with code 255.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
33.38 ms | 401 KiB | 8 Q