Skip to content

Instantly share code, notes, and snippets.

@ufhy
Created May 17, 2020 12:00
Show Gist options
  • Save ufhy/d5a5962c73edf273ab9aa5d956b077d5 to your computer and use it in GitHub Desktop.
Save ufhy/d5a5962c73edf273ab9aa5d956b077d5 to your computer and use it in GitHub Desktop.
Generate range of dates in PHP
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