Skip to content

Instantly share code, notes, and snippets.

@turtlix
Created May 13, 2016 00:58
Show Gist options
  • Save turtlix/67578f1301772fc83d49aeb826b1fce0 to your computer and use it in GitHub Desktop.
Save turtlix/67578f1301772fc83d49aeb826b1fce0 to your computer and use it in GitHub Desktop.
<?php
$start_date = new DateTime('2010-10-01');
$end_date = new DateTime('2010-10-05');
$period = new DatePeriod(
$start_date, // 1st PARAM: start date
new DateInterval('P1D'), // 2nd PARAM: interval (1 day interval in this case)
$end_date, // 3rd PARAM: end date
DatePeriod::EXCLUDE_START_DATE // 4th PARAM (optional): self-explanatory
);
foreach($period as $date) {
echo $date->format('Y-m-d').'<br/>'; // Display the dates in yyyy-mm-dd format
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment