Skip to content

Instantly share code, notes, and snippets.

@JonoB
Created October 28, 2015 15:32
Show Gist options
  • Save JonoB/9c20756e8cb184962cfb to your computer and use it in GitHub Desktop.
Save JonoB/9c20756e8cb184962cfb to your computer and use it in GitHub Desktop.
Increment PHP Months
$nextMonthDate = $date->copy();
$nextMonthDate->addMonths($addMonths);
// j - Day of the month without leading zeros
if ($nextMonthDate->format('j') != $date->format('j'))
{
$date->modify('last day of +'.$addMonths.' months');
}
else
{
$date->addMonths($addMonths);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment