- date: documentation ( source)
- strtotime: documentation ( source)
<?php
$sample1 = "2010-01-31";
$sample1a = "2010-01-01";
$dnow = date("t",strtotime($sample1));
$dnext = date("t",strtotime($sample1a . " +1 month"));
$dday = date("d",strtotime($sample1));
$output = date("Y-m-d",strtotime($sample1 . " +1 month"));
echo '/' . $dnow . '/' . $dnext . '/' . $dday . '/';
echo "\n";
if ($dnext < $dnow && $dnext < $dday)
{
$nextMonth = date("Y-m", strtotime($sample1));
$nextMonth = date("Y-m", strtotime($nextMonth . " +1 month"));
$output = $nextMonth . '-' . $dnext;
}
echo $output;
echo "\n";
$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');