Skip to content

Instantly share code, notes, and snippets.

@ronnyandre
Last active December 17, 2015 14:49
Show Gist options
  • Save ronnyandre/5626858 to your computer and use it in GitHub Desktop.
Save ronnyandre/5626858 to your computer and use it in GitHub Desktop.
Get each occurence in DatePeriod
<?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