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->y}-{$diff->m}-{$diff->d} / days: {$diff->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.3 - 7.1.0
2014-03-11 - 2014-03-11 = 0-0-0 / days: 0 2014-03-11 - 2014-03-10 = 0-0-0 / days: 0 2014-03-11 - 2014-03-09 = 0-0-1 / days: 1 2014-03-11 - 2014-03-08 = 0-0-2 / days: 2 2014-03-11 - 2014-03-07 = 0-0-3 / days: 3 2014-03-11 - 2014-03-06 = 0-0-4 / days: 4 2014-03-11 - 2014-03-05 = 0-0-5 / days: 5 2014-03-11 - 2014-03-04 = 0-0-6 / days: 6 2014-03-11 - 2014-03-03 = 0-0-7 / days: 7 2014-03-11 - 2014-03-02 = 0-0-8 / days: 8 2014-03-11 - 2014-03-01 = 0-0-9 / days: 9 2014-03-11 - 2014-02-28 = 0-0-10 / days: 10 2014-03-11 - 2014-02-27 = 0-0-11 / days: 11 2014-03-11 - 2014-02-26 = 0-0-12 / days: 12 2014-03-11 - 2014-02-25 = 0-0-13 / days: 13 2014-03-11 - 2014-02-24 = 0-0-14 / days: 14 2014-03-11 - 2014-02-23 = 0-0-15 / days: 15 2014-03-11 - 2014-02-22 = 0-0-16 / days: 16 2014-03-11 - 2014-02-21 = 0-0-17 / days: 17 2014-03-11 - 2014-02-20 = 0-0-18 / days: 18 2014-03-11 - 2014-02-19 = 0-0-19 / days: 19 2014-03-11 - 2014-02-18 = 0-0-20 / days: 20 2014-03-11 - 2014-02-17 = 0-0-21 / days: 21 2014-03-11 - 2014-02-16 = 0-0-22 / days: 22 2014-03-11 - 2014-02-15 = 0-0-23 / days: 23 2014-03-11 - 2014-02-14 = 0-0-24 / days: 24 2014-03-11 - 2014-02-13 = 0-0-25 / days: 25 2014-03-11 - 2014-02-12 = 0-0-26 / days: 26 2014-03-11 - 2014-02-11 = 0-0-27 / days: 27 2014-03-11 - 2014-02-10 = 0-1-0 / days: 28 2014-03-11 - 2014-02-09 = 0-1-1 / days: 29 2014-03-11 - 2014-02-08 = 0-1-2 / days: 30 2014-03-11 - 2014-02-07 = 0-1-3 / days: 31 2014-03-11 - 2014-02-06 = 0-1-4 / days: 32 2014-03-11 - 2014-02-05 = 0-1-5 / days: 33 2014-03-11 - 2014-02-04 = 0-1-6 / days: 34 2014-03-11 - 2014-02-03 = 0-1-7 / days: 35 2014-03-11 - 2014-02-02 = 0-1-8 / days: 36 2014-03-11 - 2014-02-01 = 0-1-9 / days: 37 2014-03-11 - 2014-01-31 = 0-1-10 / days: 38 2014-03-11 - 2014-01-30 = 0-1-11 / days: 39 2014-03-11 - 2014-01-29 = 0-1-12 / days: 40 2014-03-11 - 2014-01-28 = 0-1-13 / days: 41 2014-03-11 - 2014-01-27 = 0-1-14 / days: 42 2014-03-11 - 2014-01-26 = 0-1-15 / days: 43 2014-03-11 - 2014-01-25 = 0-1-16 / days: 44 2014-03-11 - 2014-01-24 = 0-1-17 / days: 45 2014-03-11 - 2014-01-23 = 0-1-18 / days: 46 2014-03-11 - 2014-01-22 = 0-1-19 / days: 47 2014-03-11 - 2014-01-21 = 0-1-20 / days: 48 2014-03-11 - 2014-01-20 = 0-1-21 / days: 49 2014-03-11 - 2014-01-19 = 0-1-22 / days: 50 2014-03-11 - 2014-01-18 = 0-1-23 / days: 51 2014-03-11 - 2014-01-17 = 0-1-24 / days: 52 2014-03-11 - 2014-01-16 = 0-1-25 / days: 53 2014-03-11 - 2014-01-15 = 0-1-26 / days: 54 2014-03-11 - 2014-01-14 = 0-1-27 / days: 55 2014-03-11 - 2014-01-13 = 0-1-28 / days: 56 2014-03-11 - 2014-01-12 = 0-1-29 / days: 57 2014-03-11 - 2014-01-11 = 0-1-30 / days: 58 2014-03-11 - 2014-01-10 = 0-2-0 / days: 59 2014-03-11 - 2014-01-09 = 0-2-1 / days: 60 2014-03-11 - 2014-01-08 = 0-2-2 / days: 61 2014-03-11 - 2014-01-07 = 0-2-3 / days: 62 2014-03-11 - 2014-01-06 = 0-2-4 / days: 63 2014-03-11 - 2014-01-05 = 0-2-5 / days: 64 2014-03-11 - 2014-01-04 = 0-2-6 / days: 65 2014-03-11 - 2014-01-03 = 0-2-7 / days: 66 2014-03-11 - 2014-01-02 = 0-2-8 / days: 67 2014-03-11 - 2014-01-01 = 0-2-9 / days: 68
Output for 5.3.0 - 5.3.2
2014-03-11 - 2014-03-11 = 0-0-0 / days: 0 2014-03-11 - 2014-03-10 = 0-0-0 / days: 0 2014-03-11 - 2014-03-09 = 0-0-1 / days: 1 2014-03-11 - 2014-03-08 = 0-0-2 / days: 2 2014-03-11 - 2014-03-07 = 0-0-3 / days: 3 2014-03-11 - 2014-03-06 = 0-0-4 / days: 4 2014-03-11 - 2014-03-05 = 0-0-5 / days: 5 2014-03-11 - 2014-03-04 = 0-0-6 / days: 6 2014-03-11 - 2014-03-03 = 0-0-7 / days: 7 2014-03-11 - 2014-03-02 = 0-0-8 / days: 8 2014-03-11 - 2014-03-01 = 0-0-9 / days: 9 2014-03-11 - 2014-02-28 = 0-0-10 / days: 10 2014-03-11 - 2014-02-27 = 0-0-11 / days: 11 2014-03-11 - 2014-02-26 = 0-0-12 / days: 12 2014-03-11 - 2014-02-25 = 0-0-13 / days: 13 2014-03-11 - 2014-02-24 = 0-0-14 / days: 14 2014-03-11 - 2014-02-23 = 0-0-15 / days: 15 2014-03-11 - 2014-02-22 = 0-0-16 / days: 16 2014-03-11 - 2014-02-21 = 0-0-17 / days: 17 2014-03-11 - 2014-02-20 = 0-0-18 / days: 18 2014-03-11 - 2014-02-19 = 0-0-19 / days: 19 2014-03-11 - 2014-02-18 = 0-0-20 / days: 20 2014-03-11 - 2014-02-17 = 0-0-21 / days: 21 2014-03-11 - 2014-02-16 = 0-0-22 / days: 22 2014-03-11 - 2014-02-15 = 0-0-23 / days: 23 2014-03-11 - 2014-02-14 = 0-0-24 / days: 24 2014-03-11 - 2014-02-13 = 0-0-25 / days: 25 2014-03-11 - 2014-02-12 = 0-0-26 / days: 26 2014-03-11 - 2014-02-11 = 0-0-27 / days: 27 2014-03-11 - 2014-02-10 = 0-1-0 / days: 28 2014-03-11 - 2014-02-09 = 0-1-1 / days: 29 2014-03-11 - 2014-02-08 = 0-1-2 / days: 30 2014-03-11 - 2014-02-07 = 0-1-3 / days: 31 2014-03-11 - 2014-02-06 = 0-1-4 / days: 32 2014-03-11 - 2014-02-05 = 0-1-5 / days: 33 2014-03-11 - 2014-02-04 = 0-1-6 / days: 34 2014-03-11 - 2014-02-03 = 0-1-7 / days: 35 2014-03-11 - 2014-02-02 = 0-1-8 / days: 36 2014-03-11 - 2014-02-01 = 0-1-9 / days: 37 2014-03-11 - 2014-01-31 = 0-1-10 / days: 38 2014-03-11 - 2014-01-30 = 0-1-11 / days: 39 2014-03-11 - 2014-01-29 = 0-1-12 / days: 40 2014-03-11 - 2014-01-28 = 0-1-13 / days: 41 2014-03-11 - 2014-01-27 = 0-1-14 / days: 42 2014-03-11 - 2014-01-26 = 0-1-15 / days: 43 2014-03-11 - 2014-01-25 = 0-1-16 / days: 44 2014-03-11 - 2014-01-24 = 0-1-17 / days: 45 2014-03-11 - 2014-01-23 = 0-1-18 / days: 46 2014-03-11 - 2014-01-22 = 0-1-19 / days: 47 2014-03-11 - 2014-01-21 = 0-1-20 / days: 48 2014-03-11 - 2014-01-20 = 0-1-21 / days: 49 2014-03-11 - 2014-01-19 = 0-1-22 / days: 50 2014-03-11 - 2014-01-18 = 0-1-23 / days: 51 2014-03-11 - 2014-01-17 = 0-1-24 / days: 52 2014-03-11 - 2014-01-16 = 0-1-25 / days: 53 2014-03-11 - 2014-01-15 = 0-1-26 / days: 54 2014-03-11 - 2014-01-14 = 0-1-27 / days: 55 2014-03-11 - 2014-01-13 = 0-1-28 / days: 56 2014-03-11 - 2014-01-12 = 0-2-1 / days: 57 2014-03-11 - 2014-01-11 = 0-2-2 / days: 58 2014-03-11 - 2014-01-10 = 0-2-0 / days: 59 2014-03-11 - 2014-01-09 = 0-2-1 / days: 60 2014-03-11 - 2014-01-08 = 0-2-2 / days: 61 2014-03-11 - 2014-01-07 = 0-2-3 / days: 62 2014-03-11 - 2014-01-06 = 0-2-4 / days: 63 2014-03-11 - 2014-01-05 = 0-2-5 / days: 64 2014-03-11 - 2014-01-04 = 0-2-6 / days: 65 2014-03-11 - 2014-01-03 = 0-2-7 / days: 66 2014-03-11 - 2014-01-02 = 0-2-8 / days: 67 2014-03-11 - 2014-01-01 = 0-2-9 / days: 68
Output for 5.2.10 - 5.2.17
Fatal error: Call to undefined method DateTime::createFromFormat() in /in/48j2h 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/48j2h on line 6
Process exited with code 255.
Output for 5.0.0 - 5.1.6
Fatal error: Class 'DateTime' not found in /in/48j2h on line 16
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected '(', expecting '}' in /in/48j2h 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/48j2h on line 13
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `'}'' in /in/48j2h on line 13
Process exited with code 255.