Skip to content

Instantly share code, notes, and snippets.

@plindsay
Last active March 30, 2017 19:54
Show Gist options
  • Select an option

  • Save plindsay/ab02a4b587abbe936730f33977c93257 to your computer and use it in GitHub Desktop.

Select an option

Save plindsay/ab02a4b587abbe936730f33977c93257 to your computer and use it in GitHub Desktop.
DateInterval skips February?..
$begin = new \DateTime('-3 month');
$end = new \DateTime(date('Y-m-d'));
$end = $end->modify('+1 month');
$interval = \DateInterval::createFromDateString('+1 month');
$period = new \DatePeriod($begin, $interval, $end);
foreach($period as $dt) {
$start = $dt->format('Y-m').'-01';
echo $start."<br>";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment