Skip to content

Instantly share code, notes, and snippets.

@arsenik
Last active June 7, 2018 10:43
Show Gist options
  • Save arsenik/647091bc3a9dc3a30ae4cb171f874efc to your computer and use it in GitHub Desktop.
Save arsenik/647091bc3a9dc3a30ae4cb171f874efc to your computer and use it in GitHub Desktop.
Generate a list of dates for a given date range
<?php
$s = '2018-01-25';
$e = '2018-02-26';
$interval = \DateInterval::createFromDateString('1 day');
$start_datetime = new \DateTime($s);
$end_datetime = new \DateTime($e);
$date_period = new \DatePeriod($start_datetime, $interval, $end_datetime->add(new DateInterval('P1D')));
$dates = array();
foreach ($date_period as $i => $p) {
echo $p->format('Y-m-d')."\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment