Skip to content

Instantly share code, notes, and snippets.

@mazfreelance
Created December 20, 2017 07:27
Show Gist options
  • Save mazfreelance/1097714864c1f99917cbea91166e402f to your computer and use it in GitHub Desktop.
Save mazfreelance/1097714864c1f99917cbea91166e402f to your computer and use it in GitHub Desktop.
PHP: Listed date between two dates
function getDatesFromRange($start, $end, $format = 'Y-m-d') {
$array = array();
$interval = new DateInterval('P1D');
$realEnd = new DateTime($end);
$realEnd->add($interval);
$period = new DatePeriod(new DateTime($start), $interval, $realEnd);
foreach($period as $date) {
$array[] = $date->format($format);
}
return $array;
}
// Call the function
$dates = getDatesFromRange('2017-8-10', date('Y-9-27')); // change this
// Print the output
print_r($dates);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment