3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $dob = new DateTime('24 June 1940'); $now = new DateTime('now'); echo year_diff($now, $dob); function year_diff($date1, $date2) { list($year1, $dayOfYear1) = explode(' ', $date1->format('Y z')); list($year2, $dayOfYear2) = explode(' ', $date2->format('Y z')); return $year1 - $year2 - ($dayOfYear1 < $dayOfYear2); }
based on gGMPa
Output for 5.2.0 - 5.4.38, 5.6.28, 7.0.14 - 7.1.0
74
Output for 5.4.39 - 5.6.21, 7.0.0 - 7.0.6
75
Output for 5.0.0 - 5.1.6
Fatal error: Class 'DateTime' not found in /in/UFo9g on line 3
Process exited with code 255.
Output for 4.3.2 - 4.4.9
Fatal error: Cannot instantiate non-existent class: datetime in /in/UFo9g on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Cannot instantiate non-existent class: datetime in /in/UFo9g on line 3