Created
February 23, 2018 02:22
-
-
Save aliboy08/6bf848fea743d236741477bdfcf0afef to your computer and use it in GitHub Desktop.
PHP get months between 2 dates
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
$start = new DateTime('2013-08-01'); | |
$start->modify('first day of this month'); | |
$end = new DateTime(date('Y-m-d')); // current date | |
$end->modify('first day of next month'); | |
$interval = DateInterval::createFromDateString('1 month'); | |
$period = new DatePeriod($start, $interval, $end); | |
foreach ($period as $dt) { | |
echo $dt->format("F Y"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment