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