Created
December 20, 2017 07:27
-
-
Save mazfreelance/1097714864c1f99917cbea91166e402f to your computer and use it in GitHub Desktop.
PHP: Listed date between two dates
This file contains hidden or 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
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