3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function nextMonth($thisMonth, $monthInc) { $firstOfThis = date("Y-m", strtotime($thisMonth)); $dNow = date("t", strtotime($thisMonth)); $dNext = date("t", strtotime($firstOfThis . " +" . $monthInc . " month")); $dDay = date("d", strtotime($thisMonth)); $output = date("Y-m-d",strtotime($thisMonth . " +" . $monthInc . " month")); if ($dNext < $dNow && $dNext < $dDay) { $output = date("Y-m", strtotime($firstOfThis . " +" . $monthInc . " month")) . '-' . $dNext; } return $output . "\n"; } echo nextMonth("2009-12-31",2); echo nextMonth("2010-01-31",1); echo nextMonth("2010-01-05",1); echo nextMonth("2010-12-05",1); exit(); ?>
Output for 5.2.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
2010-02-28 2010-02-28 2010-02-05 2011-01-05
Output for 4.3.0 - 5.1.6
2010-03-03 2010-03-03 2010-02-05 2011-01-05