<?php
function nextMonth($thisMonth, $monthInc)
{
$firstOfThis = date("Y-m", strtotime($thisMonth));
$dNow = date("t", strtotime($thisMonth));
$dNext = date("t", strtotime($firstOfThis . " +1 month"));
$dDay = date("d", strtotime($thisMonth));
$output = date("Y-m-d",strtotime($thisMonth . " +1 month"));
if ($dNext < $dNow && $dNext < $dDay)
{
$nextMonth = date("Y-m", strtotime($thisMonth));
$nextMonth = date("Y-m", strtotime($nextMonth . " +1 month"));
$output = $nextMonth . '-' . $dNext;
}
return $output;
}
echo nextMonth("2010-01-31",1);
$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');
preferences:
36.2 ms | 402 KiB | 5 Q