Created
May 17, 2020 12:00
-
-
Save ufhy/d5a5962c73edf273ab9aa5d956b077d5 to your computer and use it in GitHub Desktop.
Generate range of dates in PHP
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 dateRange( $first, $last, $step = '+1 day', $format = 'Y/m/d' ) { | |
$dates = array(); | |
$current = strtotime( $first ); | |
$last = strtotime( $last ); | |
while( $current <= $last ) { | |
$dates[] = date( $format, $current ); | |
$current = strtotime( $step, $current ); | |
} | |
return $dates; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment