Created
September 3, 2015 07:13
-
-
Save tenkunkyab/ae828175e2d23ce31dbd to your computer and use it in GitHub Desktop.
foreach and datePeriod Hack [source : http://php.net/manual/en/class.dateperiod.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
| <?php | |
| $begin = new DateTime( '2015-08-01' ); | |
| $end = new DateTime( '2015-08-31' ); | |
| // this way the last date is not missed in the foreach loop | |
| $end = $end->modify( '+1 day' ); | |
| $interval = new DateInterval('P1D'); | |
| $daterange = new DatePeriod($begin, $interval ,$end); | |
| foreach($daterange as $date){ | |
| echo $date->format("Y-m-d") . "<br>"; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment