3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $sample1 = "2010-01-31"; $sample1a = "2010-01-01"; $dnow = date("t",strtotime($sample1)); $dnext = date("t",strtotime($sample1a . " +1 month")); $dday = date("d",strtotime($sample1)); $output = date("Y-m-d",strtotime($sample1 . " +1 month")); echo '/' . $dnow . '/' . $dnext . '/' . $dday . '/'; echo "\n"; if ($dnext < $dnow && $dnext < $dday) { $nextMonth = date("Y-m", strtotime($sample1)); $nextMonth = date("Y-m", strtotime($nextMonth . " +1 month")); $output = $nextMonth . '-' . $dnext; } echo $output; echo "\n"; $ts = strtotime('2010-01-31 +1 month'); echo date('Y-m-d', $ts); echo "\n"; $dt = new \DateTime('2010-01-31'); $dt->add(new \DateInterval('P1M')); echo $dt->format('Y-m-d'); echo "\n"; $ts = strtotime('2010-01-05 +1 month'); echo date('Y-m-d', $ts); echo "\n"; $dt = new \DateTime('2010-01-05'); $dt->add(new \DateInterval('P1M')); echo $dt->format('Y-m-d');
Output for 5.3.0 - 7.1.0
/31/28/31/ 2010-02-28 2010-03-03 2010-03-03 2010-02-05 2010-02-05
Output for 5.2.0 - 5.2.17
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/f4hIK on line 22 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/f4hIK on line 23 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/f4hIK on line 29 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/f4hIK on line 30 /31/28/31/ 2010-02-28 2010-03-03 Fatal error: Call to undefined method DateTime::add() in /in/f4hIK on line 23
Process exited with code 255.
Output for 5.1.0 - 5.1.6
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/f4hIK on line 22 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/f4hIK on line 23 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/f4hIK on line 29 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/f4hIK on line 30 /31/28/31/ 2013-12-28 2010-03-03 Fatal error: Class 'DateTime' not found in /in/f4hIK on line 22
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/f4hIK on line 22 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/f4hIK on line 23 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/f4hIK on line 29 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/f4hIK on line 30 /31/28/31/ 2010-01-28 2010-03-03 Fatal error: Class 'DateTime' not found in /in/f4hIK on line 22
Process exited with code 255.
Output for 4.3.2 - 4.4.9
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/f4hIK on line 22 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/f4hIK on line 23 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/f4hIK on line 29 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/f4hIK on line 30 /31/28/31/ 2010-01-28 2010-03-03 Fatal error: Cannot instantiate non-existent class: datetime in /in/f4hIK on line 22
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/f4hIK on line 22 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/f4hIK on line 23 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/f4hIK on line 29 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/f4hIK on line 30 /31/28/31/ 2010-01-28 2010-03-03 Fatal error: Cannot instantiate non-existent class: datetime in /in/f4hIK on line 22