Created
March 26, 2014 09:41
-
-
Save daithi-coombes/9779776 to your computer and use it in GitHub Desktop.
Get an array of months between two dates
This file contains 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
$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