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 H:i:s',$dob); //current date $nowObject = new DateTime('2014-03-11 00:00:00'); //difference $diff = $nowObject->diff($dobObject); return "{$nowObject->format('Y-m-d H:i:s')} - {$nowObject->format('Y-m-d H:i:s')} = {$diff->format('%r%Y-%M-%D %H:%I:%S')} = {$diff->format('%r%a')} days"; } $date = new DateTime('2014-03-12 00:00:00'); while ($date >= new DateTime('2014-01-01 00:00:00')) { echo ageMonths($date->format('Y-m-d H:i:s')), PHP_EOL; $date->sub(new DateInterval('P1D')); }
Output for 5.5.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
2014-03-11 00:00:00 - 2014-03-11 00:00:00 = 00-00-01 00:00:00 = 1 days 2014-03-11 00:00:00 - 2014-03-11 00:00:00 = 00-00-00 00:00:00 = 0 days 2014-03-11 00:00:00 - 2014-03-11 00:00:00 = -00-00-01 00:00:00 = -1 days 2014-03-11 00:00:00 - 2014-03-11 00:00:00 = -00-00-02 00:00:00 = -2 days 2014-03-11 00:00:00 - 2014-03-11 00:00:00 = -00-00-03 00:00:00 = -3 days 2014-03-11 00:00:00 - 2014-03-11 00:00:00 = -00-00-04 00:00:00 = -4 days 2014-03-11 00:00:00 - 2014-03-11 00:00:00 = -00-00-05 00:00:00 = -5 days 2014-03-11 00:00:00 - 2014-03-11 00:00:00 = -00-00-06 00:00:00 = -6 days 2014-03-11 00:00:00 - 2014-03-11 00:00:00 = -00-00-07 00:00:00 = -7 days 2014-03-11 00:00:00 - 2014-03-11 00:00:00 = -00-00-08 00:00:00 = -8 days 2014-03-11 00:00:00 - 2014-03-11 00:00:00 = -00-00-09 00:00:00 = -9 days 2014-03-11 00:00:00 - 2014-03-11 00:00:00 = -00-00-10 00:00:00 = -10 days 2014-03-11 00:00:00 - 2014-03-11 00:00:00 = -00-00-11 00:00:00 = -11 days 2014-03-11 00:00:00 - 2014-03-11 00:00:00 = -00-00-12 00:00:00 = -12 days 2014-03-11 00:00:00 - 2014-03-11 00:00:00 = -00-00-13 00:00:00 = -13 days 2014-03-11 00:00:00 - 2014-03-11 00:00:00 = -00-00-14 00:00:00 = -14 days 2014-03-11 00:00:00 - 2014-03-11 00:00:00 = -00-00-15 00:00:00 = -15 days 2014-03-11 00:00:00 - 2014-03-11 00:00:00 = -00-00-16 00:00:00 = -16 days 2014-03-11 00:00:00 - 2014-03-11 00:00:00 = -00-00-17 00:00:00 = -17 days 2014-03-11 00:00:00 - 2014-03-11 00:00:00 = -00-00-18 00:00:00 = -18 days 2014-03-11 00:00:00 - 2014-03-11 00:00:00 = -00-00-19 00:00:00 = -19 days 2014-03-11 00:00:00 - 2014-03-11 00:00:00 = -00-00-20 00:00:00 = -20 days 2014-03-11 00:00:00 - 2014-03-11 00:00:00 = -00-00-21 00:00:00 = -21 days 2014-03-11 00:00:00 - 2014-03-11 00:00:00 = -00-00-22 00:00:00 = -22 days 2014-03-11 00:00:00 - 2014-03-11 00:00:00 = -00-00-23 00:00:00 = -23 days 2014-03-11 00:00:00 - 2014-03-11 00:00:00 = -00-00-24 00:00:00 = -24 days 2014-03-11 00:00:00 - 2014-03-11 00:00:00 = -00-00-25 00:00:00 = -25 days 2014-03-11 00:00:00 - 2014-03-11 00:00:00 = -00-00-26 00:00:00 = -26 days 2014-03-11 00:00:00 - 2014-03-11 00:00:00 = -00-00-27 00:00:00 = -27 days 2014-03-11 00:00:00 - 2014-03-11 00:00:00 = -00-01-00 00:00:00 = -28 days 2014-03-11 00:00:00 - 2014-03-11 00:00:00 = -00-01-01 00:00:00 = -29 days 2014-03-11 00:00:00 - 2014-03-11 00:00:00 = -00-01-02 00:00:00 = -30 days 2014-03-11 00:00:00 - 2014-03-11 00:00:00 = -00-01-03 00:00:00 = -31 days 2014-03-11 00:00:00 - 2014-03-11 00:00:00 = -00-01-04 00:00:00 = -32 days 2014-03-11 00:00:00 - 2014-03-11 00:00:00 = -00-01-05 00:00:00 = -33 days 2014-03-11 00:00:00 - 2014-03-11 00:00:00 = -00-01-06 00:00:00 = -34 days 2014-03-11 00:00:00 - 2014-03-11 00:00:00 = -00-01-07 00:00:00 = -35 days 2014-03-11 00:00:00 - 2014-03-11 00:00:00 = -00-01-08 00:00:00 = -36 days 2014-03-11 00:00:00 - 2014-03-11 00:00:00 = -00-01-09 00:00:00 = -37 days 2014-03-11 00:00:00 - 2014-03-11 00:00:00 = -00-01-10 00:00:00 = -38 days 2014-03-11 00:00:00 - 2014-03-11 00:00:00 = -00-01-11 00:00:00 = -39 days 2014-03-11 00:00:00 - 2014-03-11 00:00:00 = -00-01-12 00:00:00 = -40 days 2014-03-11 00:00:00 - 2014-03-11 00:00:00 = -00-01-13 00:00:00 = -41 days 2014-03-11 00:00:00 - 2014-03-11 00:00:00 = -00-01-14 00:00:00 = -42 days 2014-03-11 00:00:00 - 2014-03-11 00:00:00 = -00-01-15 00:00:00 = -43 days 2014-03-11 00:00:00 - 2014-03-11 00:00:00 = -00-01-16 00:00:00 = -44 days 2014-03-11 00:00:00 - 2014-03-11 00:00:00 = -00-01-17 00:00:00 = -45 days 2014-03-11 00:00:00 - 2014-03-11 00:00:00 = -00-01-18 00:00:00 = -46 days 2014-03-11 00:00:00 - 2014-03-11 00:00:00 = -00-01-19 00:00:00 = -47 days 2014-03-11 00:00:00 - 2014-03-11 00:00:00 = -00-01-20 00:00:00 = -48 days 2014-03-11 00:00:00 - 2014-03-11 00:00:00 = -00-01-21 00:00:00 = -49 days 2014-03-11 00:00:00 - 2014-03-11 00:00:00 = -00-01-22 00:00:00 = -50 days 2014-03-11 00:00:00 - 2014-03-11 00:00:00 = -00-01-23 00:00:00 = -51 days 2014-03-11 00:00:00 - 2014-03-11 00:00:00 = -00-01-24 00:00:00 = -52 days 2014-03-11 00:00:00 - 2014-03-11 00:00:00 = -00-01-25 00:00:00 = -53 days 2014-03-11 00:00:00 - 2014-03-11 00:00:00 = -00-01-26 00:00:00 = -54 days 2014-03-11 00:00:00 - 2014-03-11 00:00:00 = -00-01-27 00:00:00 = -55 days 2014-03-11 00:00:00 - 2014-03-11 00:00:00 = -00-01-28 00:00:00 = -56 days 2014-03-11 00:00:00 - 2014-03-11 00:00:00 = -00-01-29 00:00:00 = -57 days 2014-03-11 00:00:00 - 2014-03-11 00:00:00 = -00-01-30 00:00:00 = -58 days 2014-03-11 00:00:00 - 2014-03-11 00:00:00 = -00-02-00 00:00:00 = -59 days 2014-03-11 00:00:00 - 2014-03-11 00:00:00 = -00-02-01 00:00:00 = -60 days 2014-03-11 00:00:00 - 2014-03-11 00:00:00 = -00-02-02 00:00:00 = -61 days 2014-03-11 00:00:00 - 2014-03-11 00:00:00 = -00-02-03 00:00:00 = -62 days 2014-03-11 00:00:00 - 2014-03-11 00:00:00 = -00-02-04 00:00:00 = -63 days 2014-03-11 00:00:00 - 2014-03-11 00:00:00 = -00-02-05 00:00:00 = -64 days 2014-03-11 00:00:00 - 2014-03-11 00:00:00 = -00-02-06 00:00:00 = -65 days 2014-03-11 00:00:00 - 2014-03-11 00:00:00 = -00-02-07 00:00:00 = -66 days 2014-03-11 00:00:00 - 2014-03-11 00:00:00 = -00-02-08 00:00:00 = -67 days 2014-03-11 00:00:00 - 2014-03-11 00:00:00 = -00-02-09 00:00:00 = -68 days 2014-03-11 00:00:00 - 2014-03-11 00:00:00 = -00-02-10 00:00:00 = -69 days
Output for 5.4.0 - 5.4.45
Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone.' in /in/YQsWX:16 Stack trace: #0 /in/YQsWX(16): DateTime->__construct('2014-03-12 00:0...') #1 {main} thrown in /in/YQsWX on line 16
Process exited with code 255.
Output for 5.3.0 - 5.3.29
Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/Berlin' for 'CEST/2.0/DST' instead' in /in/YQsWX:16 Stack trace: #0 /in/YQsWX(16): DateTime->__construct('2014-03-12 00:0...') #1 {main} thrown in /in/YQsWX on line 16
Process exited with code 255.
Output for 5.2.10 - 5.2.17
Fatal error: Call to undefined method DateTime::createFromFormat() in /in/YQsWX on line 6
Process exited with code 255.
Output for 5.2.3 - 5.2.9
Fatal error: Call to undefined method DateTime::createfromformat() in /in/YQsWX on line 6
Process exited with code 255.
Output for 5.2.0 - 5.2.2
<br /> <b>Fatal error</b>: Call to undefined method DateTime::createfromformat() in <b>/in/YQsWX</b> on line <b>6</b><br />
Process exited with code 255.
Output for 5.0.0 - 5.1.6
<br /> <b>Fatal error</b>: Class 'DateTime' not found in <b>/in/YQsWX</b> on line <b>16</b><br />
Process exited with code 255.
Output for 4.4.2 - 4.4.9
<br /> <b>Parse error</b>: syntax error, unexpected '(', expecting '}' in <b>/in/YQsWX</b> on line <b>13</b><br />
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
<br /> <b>Parse error</b>: parse error, unexpected '(', expecting '}' in <b>/in/YQsWX</b> on line <b>13</b><br />
Process exited with code 255.
Output for 4.3.2 - 4.3.4
<br /> <b>Parse error</b>: parse error, expecting `'}'' in <b>/in/YQsWX</b> on line <b>13</b><br />
Process exited with code 255.