3v4l.org

run code in 300+ PHP versions simultaneously
<?php $date = new DateTime( '2016-08-25' ); echo $date->format('Y-m-d'),"\n"; $day = $date->format('j'); $date->modify('first day of sixth month'); $date->modify('+' . (min($day, $date->format('t')) - 1) . ' days'); echo $date->format('Y-m-d');

preferences:
62.08 ms | 404 KiB | 5 Q