<?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";
preferences:
38.44 ms | 402 KiB | 5 Q