- date: documentation ( source)
- strtotime: documentation ( source)
<?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";
$ts1 = strtotime('2010-01-31 +1 month');
$ts2 = strtotime('first day of next month');
$ts3 = strtotime('last day of this month', $ts2);
$ts = $ts1;
if ($ts1 > $ts3) {
$ts = $ts3;
}
echo date('Y-m-d', $ts);
echo date('Y-m-d', $ts1);
echo date('Y-m-d', $ts2);
echo date('Y-m-d', $ts3);