Skip to content

Instantly share code, notes, and snippets.

@aliboy08
Created February 23, 2018 02:22
Show Gist options
  • Save aliboy08/6bf848fea743d236741477bdfcf0afef to your computer and use it in GitHub Desktop.
Save aliboy08/6bf848fea743d236741477bdfcf0afef to your computer and use it in GitHub Desktop.
PHP get months between 2 dates
$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