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