Created
March 29, 2016 16:23
-
-
Save johnabela/56d080ecf4778da4154d to your computer and use it in GitHub Desktop.
This file contains 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
$start = new DateTime('now'); | |
$end = new DateTime('- 7 day'); | |
$diff = $end->diff($start); | |
$interval = DateInterval::createFromDateString('-1 day'); | |
$period = new DatePeriod($start, $interval, $diff->days); | |
foreach ($period as $date) { | |
echo $date->format('m-d') . '<br>'; // or whatever you want to do | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can we not just use
$end
as the last argument? That way there's no need to add clutter with$diff
.(According to /manual/en/dateperiod.construct.php)