Last active
February 28, 2017 15:37
-
-
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 :)
This file contains hidden or 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
<?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