Created
January 28, 2013 14:37
-
-
Save crishnakh/4655997 to your computer and use it in GitHub Desktop.
Array days between two dates
source: http://boonedocks.net/mike/archives/137-Creating-a-Date-Range-Array-with-PHP.html
http://stackoverflow.com/questions/4312439/php-return-all-dates-between-two-dates-in-an-array
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
<?php | |
function createDateRangeArray($strDateFrom,$strDateTo) | |
{ | |
// takes two dates formatted as YYYY-MM-DD and creates an | |
// inclusive array of the dates between the from and to dates. | |
// could test validity of dates here but I'm already doing | |
// that in the main script | |
$aryRange=array(); | |
$iDateFrom=mktime(1,0,0,substr($strDateFrom,5,2), substr($strDateFrom,8,2),substr($strDateFrom,0,4)); | |
$iDateTo=mktime(1,0,0,substr($strDateTo,5,2), substr($strDateTo,8,2),substr($strDateTo,0,4)); | |
if ($iDateTo>=$iDateFrom) | |
{ | |
array_push($aryRange,date('Y-m-d',$iDateFrom)); // first entry | |
while ($iDateFrom<$iDateTo) | |
{ | |
$iDateFrom+=86400; // add 24 hours | |
array_push($aryRange,date('Y-m-d',$iDateFrom)); | |
} | |
} | |
return $aryRange; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment