Created
April 30, 2014 18:05
-
-
Save bretdavidson/80761475ec6a57aa11ac to your computer and use it in GitHub Desktop.
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 | |
// Takes two dates formatted as YYYY-MM-DD and creates an | |
// inclusive array of the dates between the from and to dates. | |
// Taken from: http://stackoverflow.com/a/4312491 | |
function createDateRangeArray($sDate, $eDate) | |
{ | |
$range = array(); | |
$sTimestamp = mktime(1, 0, 0, substr($sDate, 5, 2), substr($sDate, 8, 2), substr($sDate, 0, 4)); | |
$eTimestamp = mktime(1, 0, 0, substr($eDate, 5, 2), substr($eDate, 8, 2), substr($eDate, 0, 4)); | |
if ($eTimestamp >= $sTimestamp) | |
{ | |
array_push($range, date('Y-m-d', $sTimestamp)); // first entry | |
while ($sTimestamp < $eTimestamp) | |
{ | |
$sTimestamp += 86400; // add 24 hours | |
array_push($range, date('Y-m-d', $iDateFrom)); | |
} | |
} | |
return $range; | |
} | |
// Date Period Object | |
// Taken from: http://stackoverflow.com/a/4312630 | |
$period = new DatePeriod( | |
new DateTime('2010-10-01'), | |
new DateInterval('P1D'), | |
new DateTime('2010-10-05') | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment