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 "{$nowObject->format('Y-m-d')} - $dob = {$diff->format('Y-m-d')} = {$diff->days} days"; } $date = new DateTime('2014-03-11'); while ($date >= new DateTime('2014-01-01')) { echo ageMonths($date->format('Y-m-d')), PHP_EOL; $date->sub(new DateInterval('P1D')); }
Output for 5.3.0 - 5.6.28, hhvm-3.12.0, 7.0.0 - 7.1.0
2014-03-11 - 2014-03-11 = Y-m-d = 0 days 2014-03-11 - 2014-03-10 = Y-m-d = 0 days 2014-03-11 - 2014-03-09 = Y-m-d = 1 days 2014-03-11 - 2014-03-08 = Y-m-d = 2 days 2014-03-11 - 2014-03-07 = Y-m-d = 3 days 2014-03-11 - 2014-03-06 = Y-m-d = 4 days 2014-03-11 - 2014-03-05 = Y-m-d = 5 days 2014-03-11 - 2014-03-04 = Y-m-d = 6 days 2014-03-11 - 2014-03-03 = Y-m-d = 7 days 2014-03-11 - 2014-03-02 = Y-m-d = 8 days 2014-03-11 - 2014-03-01 = Y-m-d = 9 days 2014-03-11 - 2014-02-28 = Y-m-d = 10 days 2014-03-11 - 2014-02-27 = Y-m-d = 11 days 2014-03-11 - 2014-02-26 = Y-m-d = 12 days 2014-03-11 - 2014-02-25 = Y-m-d = 13 days 2014-03-11 - 2014-02-24 = Y-m-d = 14 days 2014-03-11 - 2014-02-23 = Y-m-d = 15 days 2014-03-11 - 2014-02-22 = Y-m-d = 16 days 2014-03-11 - 2014-02-21 = Y-m-d = 17 days 2014-03-11 - 2014-02-20 = Y-m-d = 18 days 2014-03-11 - 2014-02-19 = Y-m-d = 19 days 2014-03-11 - 2014-02-18 = Y-m-d = 20 days 2014-03-11 - 2014-02-17 = Y-m-d = 21 days 2014-03-11 - 2014-02-16 = Y-m-d = 22 days 2014-03-11 - 2014-02-15 = Y-m-d = 23 days 2014-03-11 - 2014-02-14 = Y-m-d = 24 days 2014-03-11 - 2014-02-13 = Y-m-d = 25 days 2014-03-11 - 2014-02-12 = Y-m-d = 26 days 2014-03-11 - 2014-02-11 = Y-m-d = 27 days 2014-03-11 - 2014-02-10 = Y-m-d = 28 days 2014-03-11 - 2014-02-09 = Y-m-d = 29 days 2014-03-11 - 2014-02-08 = Y-m-d = 30 days 2014-03-11 - 2014-02-07 = Y-m-d = 31 days 2014-03-11 - 2014-02-06 = Y-m-d = 32 days 2014-03-11 - 2014-02-05 = Y-m-d = 33 days 2014-03-11 - 2014-02-04 = Y-m-d = 34 days 2014-03-11 - 2014-02-03 = Y-m-d = 35 days 2014-03-11 - 2014-02-02 = Y-m-d = 36 days 2014-03-11 - 2014-02-01 = Y-m-d = 37 days 2014-03-11 - 2014-01-31 = Y-m-d = 38 days 2014-03-11 - 2014-01-30 = Y-m-d = 39 days 2014-03-11 - 2014-01-29 = Y-m-d = 40 days 2014-03-11 - 2014-01-28 = Y-m-d = 41 days 2014-03-11 - 2014-01-27 = Y-m-d = 42 days 2014-03-11 - 2014-01-26 = Y-m-d = 43 days 2014-03-11 - 2014-01-25 = Y-m-d = 44 days 2014-03-11 - 2014-01-24 = Y-m-d = 45 days 2014-03-11 - 2014-01-23 = Y-m-d = 46 days 2014-03-11 - 2014-01-22 = Y-m-d = 47 days 2014-03-11 - 2014-01-21 = Y-m-d = 48 days 2014-03-11 - 2014-01-20 = Y-m-d = 49 days 2014-03-11 - 2014-01-19 = Y-m-d = 50 days 2014-03-11 - 2014-01-18 = Y-m-d = 51 days 2014-03-11 - 2014-01-17 = Y-m-d = 52 days 2014-03-11 - 2014-01-16 = Y-m-d = 53 days 2014-03-11 - 2014-01-15 = Y-m-d = 54 days 2014-03-11 - 2014-01-14 = Y-m-d = 55 days 2014-03-11 - 2014-01-13 = Y-m-d = 56 days 2014-03-11 - 2014-01-12 = Y-m-d = 57 days 2014-03-11 - 2014-01-11 = Y-m-d = 58 days 2014-03-11 - 2014-01-10 = Y-m-d = 59 days 2014-03-11 - 2014-01-09 = Y-m-d = 60 days 2014-03-11 - 2014-01-08 = Y-m-d = 61 days 2014-03-11 - 2014-01-07 = Y-m-d = 62 days 2014-03-11 - 2014-01-06 = Y-m-d = 63 days 2014-03-11 - 2014-01-05 = Y-m-d = 64 days 2014-03-11 - 2014-01-04 = Y-m-d = 65 days 2014-03-11 - 2014-01-03 = Y-m-d = 66 days 2014-03-11 - 2014-01-02 = Y-m-d = 67 days 2014-03-11 - 2014-01-01 = Y-m-d = 68 days
Output for hhvm-3.10.0

Process exited with code 153.
Output for 5.2.10 - 5.2.17
Fatal error: Call to undefined method DateTime::createFromFormat() in /in/MLBYT on line 6
Process exited with code 255.
Output for 5.2.0 - 5.2.9
Fatal error: Call to undefined method DateTime::createfromformat() in /in/MLBYT on line 6
Process exited with code 255.
Output for 5.0.0 - 5.1.6
Fatal error: Class 'DateTime' not found in /in/MLBYT on line 16
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected '(', expecting '}' in /in/MLBYT on line 13
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected '(', expecting '}' in /in/MLBYT on line 13
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `'}'' in /in/MLBYT on line 13
Process exited with code 255.