Created
October 28, 2015 15:32
-
-
Save JonoB/9c20756e8cb184962cfb to your computer and use it in GitHub Desktop.
Increment PHP Months
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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