Skip to content

Instantly share code, notes, and snippets.

@mrded
Last active August 29, 2015 14:06
Show Gist options
  • Save mrded/1029f76518a9d8055e4f to your computer and use it in GitHub Desktop.
Save mrded/1029f76518a9d8055e4f to your computer and use it in GitHub Desktop.
PHP: Generate range of dates
<?php
function _date_range($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;
}
var_dump(_date_range('1 month ago', 'now'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment