3v4l.org

run code in 300+ PHP versions simultaneously
<?php $ts = strtotime('2010-01-31 +1 month'); echo date('Y-m-d', $ts),"\n"; $dt = new \DateTime('2010-01-31'); $dt->add(new \DateInterval('P1M')); echo $dt->format('Y-m-d'),"\n"; $ts = strtotime('2010-01-05 +1 month'); echo date('Y-m-d', $ts),"\n"; $dt = new \DateTime('2010-01-05'); $dt->add(new \DateInterval('P1M')); echo $dt->format('Y-m-d'),"\n"; $orig = strtotime('2010-01-31'); $ts1 = strtotime('+1 month', $orig); $ts2 = strtotime('first day of next month', $orig); $ts3 = strtotime('last day of this month', $ts2); $ts = $ts1; if ($ts1 > $ts3) { $ts = $ts3; } echo date('Y-m-d', $ts),"\n"; echo date('Y-m-d', $ts1),"\n"; echo date('Y-m-d', $ts2),"\n"; echo date('Y-m-d', $ts3),"\n";

preferences:
34.71 ms | 402 KiB | 5 Q