3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $date_1 = new DateTime('2017-01-01'); $date_2 = new DateTime('2017-02-01'); $date_3 = new DateTime('2017-03-01'); $date_4 = new DateTime('2017-04-01'); $date_5 = new DateTime('2017-05-01'); $date_6 = new DateTime('2017-06-01'); $date_7 = new DateTime('2017-07-01'); $date_8 = new DateTime('2017-08-01'); $date_9 = new DateTime('2017-09-01'); $date_10 = new DateTime('2017-10-01'); $date_11 = new DateTime('2017-11-01'); $date_12 = new DateTime('2017-12-01'); $date_13 = new DateTime('2018-01-01'); echo $date_1->diff($date_2)->format('%m month, %d days') . "\n"; echo $date_2->diff($date_3)->format('%m month, %d days') . "\n"; echo $date_3->diff($date_4)->format('%m month, %d days') . "\n"; echo $date_4->diff($date_5)->format('%m month, %d days') . "\n"; echo $date_5->diff($date_6)->format('%m month, %d days') . "\n"; echo $date_6->diff($date_7)->format('%m month, %d days') . "\n"; echo $date_7->diff($date_8)->format('%m month, %d days') . "\n"; echo $date_8->diff($date_9)->format('%m month, %d days') . "\n"; echo $date_9->diff($date_10)->format('%m month, %d days') . "\n"; echo $date_10->diff($date_11)->format('%m month, %d days') . "\n"; echo $date_11->diff($date_12)->format('%m month, %d days') . "\n"; echo $date_12->diff($date_13)->format('%m month, %d days') . "\n";
based on R3LLN
Output for 5.3.0 - 5.6.30, hhvm-3.10.1 - 3.22.0, 7.0.0 - 7.2.6
1 month, 0 days 0 month, 28 days 1 month, 3 days 0 month, 30 days 1 month, 1 days 0 month, 30 days 1 month, 1 days 1 month, 0 days 0 month, 30 days 1 month, 1 days 0 month, 30 days 1 month, 1 days
Output for 5.2.0 - 5.2.17
Fatal error: Call to undefined method DateTime::diff() in /in/1b6fj on line 16
Process exited with code 255.
Output for 5.0.0 - 5.1.6
Fatal error: Class 'DateTime' not found in /in/1b6fj on line 3
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_OBJECT_OPERATOR, expecting ',' or ';' in /in/1b6fj on line 16
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_OBJECT_OPERATOR, expecting ',' or ';' in /in/1b6fj on line 16
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `','' or `';'' in /in/1b6fj on line 16
Process exited with code 255.