Skip to content

Instantly share code, notes, and snippets.

@CoolGoose
Last active February 28, 2017 15:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CoolGoose/ceb075287c754a086e8d7ee00cb7550e to your computer and use it in GitHub Desktop.
Save CoolGoose/ceb075287c754a086e8d7ee00cb7550e to your computer and use it in GitHub Desktop.
Get an array of months between two dates in PHP for table based reports :)
<?php
generateTableMappings($raw_start_date, $raw_end_date)
{
$start_date = \Datetime::createFromFormat('Y-m', $raw_start_date);
$end_date = \Datetime::createFromFormat('Y-m', $raw_end_date);
$iteration_date = clone $start_date;
$tables = [];
while ($iteration_date <= $end_date) {
$tables[] = $iteration_date->format('Y_m');
$iteration_date->add(new \DateInterval('P1M'));
}
return $tables;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment