Skip to content

Instantly share code, notes, and snippets.

@bretdavidson
Created April 30, 2014 18:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bretdavidson/80761475ec6a57aa11ac to your computer and use it in GitHub Desktop.
Save bretdavidson/80761475ec6a57aa11ac to your computer and use it in GitHub Desktop.
<?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