3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function ageMonths($dob) { //new date time $dob must be Y-m-d format $dobObject = DateTime::createFromFormat('Y-m-d',$dob); //current date $nowObject = new DateTime('2014-03-11'); //difference $diff = $nowObject->diff($dobObject); return $diff->y.'.'.$diff->m; } $date = new DateTime('2014-03-11'); while ($date > new DateTime('2014-01-01')) { $date->sub(new DateInterval('P1D')); var_dump(ageMonths($date->format('Y-m-d'))); }
Output for 5.3.3 - 7.1.0
string(3) "0.0" string(3) "0.0" string(3) "0.0" string(3) "0.0" string(3) "0.0" string(3) "0.0" string(3) "0.0" string(3) "0.0" string(3) "0.0" string(3) "0.0" string(3) "0.0" string(3) "0.0" string(3) "0.0" string(3) "0.0" string(3) "0.0" string(3) "0.0" string(3) "0.0" string(3) "0.0" string(3) "0.0" string(3) "0.0" string(3) "0.0" string(3) "0.0" string(3) "0.0" string(3) "0.0" string(3) "0.0" string(3) "0.0" string(3) "0.0" string(3) "0.0" string(3) "0.1" string(3) "0.1" string(3) "0.1" string(3) "0.1" string(3) "0.1" string(3) "0.1" string(3) "0.1" string(3) "0.1" string(3) "0.1" string(3) "0.1" string(3) "0.1" string(3) "0.1" string(3) "0.1" string(3) "0.1" string(3) "0.1" string(3) "0.1" string(3) "0.1" string(3) "0.1" string(3) "0.1" string(3) "0.1" string(3) "0.1" string(3) "0.1" string(3) "0.1" string(3) "0.1" string(3) "0.1" string(3) "0.1" string(3) "0.1" string(3) "0.1" string(3) "0.1" string(3) "0.1" string(3) "0.1" string(3) "0.2" string(3) "0.2" string(3) "0.2" string(3) "0.2" string(3) "0.2" string(3) "0.2" string(3) "0.2" string(3) "0.2" string(3) "0.2" string(3) "0.2"
Output for 5.3.0 - 5.3.2
string(3) "0.0" string(3) "0.0" string(3) "0.0" string(3) "0.0" string(3) "0.0" string(3) "0.0" string(3) "0.0" string(3) "0.0" string(3) "0.0" string(3) "0.0" string(3) "0.0" string(3) "0.0" string(3) "0.0" string(3) "0.0" string(3) "0.0" string(3) "0.0" string(3) "0.0" string(3) "0.0" string(3) "0.0" string(3) "0.0" string(3) "0.0" string(3) "0.0" string(3) "0.0" string(3) "0.0" string(3) "0.0" string(3) "0.0" string(3) "0.0" string(3) "0.0" string(3) "0.1" string(3) "0.1" string(3) "0.1" string(3) "0.1" string(3) "0.1" string(3) "0.1" string(3) "0.1" string(3) "0.1" string(3) "0.1" string(3) "0.1" string(3) "0.1" string(3) "0.1" string(3) "0.1" string(3) "0.1" string(3) "0.1" string(3) "0.1" string(3) "0.1" string(3) "0.1" string(3) "0.1" string(3) "0.1" string(3) "0.1" string(3) "0.1" string(3) "0.1" string(3) "0.1" string(3) "0.1" string(3) "0.1" string(3) "0.1" string(3) "0.1" string(3) "0.1" string(3) "0.2" string(3) "0.2" string(3) "0.2" string(3) "0.2" string(3) "0.2" string(3) "0.2" string(3) "0.2" string(3) "0.2" string(3) "0.2" string(3) "0.2" string(3) "0.2" string(3) "0.2"
Output for 5.2.2 - 5.2.17
Fatal error: Call to undefined method DateTime::sub() in /in/1m8RV on line 19
Process exited with code 255.
Output for 5.2.0 - 5.2.1
Output for 5.0.0 - 5.1.6
Fatal error: Class 'DateTime' not found in /in/1m8RV on line 16
Process exited with code 255.
Output for 4.3.2 - 4.4.9
Fatal error: Cannot instantiate non-existent class: datetime in /in/1m8RV on line 16
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Cannot instantiate non-existent class: datetime in /in/1m8RV on line 16