3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $date = new DateTime('2016-05-31'); echo $date->format('Y-m-d') . PHP_EOL; echo $date->modify('-1 month')->format('Y-m-d') . PHP_EOL; echo PHP_EOL; $date = new DateTime('2016-05-31'); echo $date->format('Y-m-d') . PHP_EOL; echo $date->modify('+1 month')->format('Y-m-d') . PHP_EOL; echo PHP_EOL; $date = new DateTime('2016-07-01'); echo $date->format('Y-m-d') . PHP_EOL; echo $date->modify('-1 month')->format('Y-m-d') . PHP_EOL;
based on g0deg
Output for 5.6.0 - 5.6.30, hhvm-3.15.4, 7.0.0 - 7.2.6
2016-05-31 2016-05-01 2016-05-31 2016-07-01 2016-07-01 2016-06-01