- 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";
$ts = strtotime('2010-02-31');
$ts1 = strtotime('2010-02-01');
$ts2 = strtotime('last day of this month', $ts1);
echo date('Y-m-d', $ts2);