Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?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
You can’t perform that action at this time.