3v4l.org

run code in 300+ PHP versions simultaneously
<?php $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'); echo "\n"; $ts = strtotime('2010-02-31'); $ts1 = strtotime('2010-02-01'); $ts2 = strtotime('last day of month', $ts1); echo date('Y-m-d', $ts2);

preferences:
37.55 ms | 402 KiB | 5 Q