Last active
December 17, 2015 14:49
-
-
Save ronnyandre/5626858 to your computer and use it in GitHub Desktop.
Get each occurence in DatePeriod
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
<?php | |
// Found at http://www.php.net/manual/en/class.dateperiod.php | |
// Credit goes to jkaatz at gmx dot de | |
// ************************************************ | |
// Nice example from PHP Spring Conference (thanks to Johannes Schlüter and David Zülke) | |
$begin = new DateTime('2013-05-01 00:00:00'); | |
$end = new DateTime('2013-12-31 23:59:59'); | |
$interval = DateInterval::createFromDateString('last thursday of next month'); | |
$period = new DatePeriod($begin, $interval, $end, DatePeriod::EXCLUDE_START_DATE); | |
foreach ($period as $dt) | |
echo $dt->format('l Y-m-d H:i:s') . '<br />'; | |
// DateInterval specs could be found at http://en.wikipedia.org/wiki/ISO_8601#Time_intervals | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment