Last active
August 29, 2015 14:06
-
-
Save mrded/1029f76518a9d8055e4f to your computer and use it in GitHub Desktop.
PHP: Generate range of 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
<?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