Skip to content

Instantly share code, notes, and snippets.

@daithi-coombes
Created March 26, 2014 09:41
Show Gist options
  • Save daithi-coombes/9779776 to your computer and use it in GitHub Desktop.
Save daithi-coombes/9779776 to your computer and use it in GitHub Desktop.
Get an array of months between two dates
$StartDate = @strtotime("Jan 2003");
$StopDate = @strtotime("Apr 2004");
/**
* Gets list of months between two dates
* @param int $start Unix timestamp
* @param int $end Unix timestamp
* @return array
*/
function echoDate( $start, $end ){
$current = $start;
$ret = array();
while( $current<$end ){
$next = @date('Y-M-01', $current) . "+1 month";
$current = @strtotime($next);
$ret[] = $current;
}
return array_reverse($ret);
}
$months = echoDate( $StartDate, $StopDate );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment