Skip to content

Instantly share code, notes, and snippets.

@tenkunkyab
Created September 3, 2015 07:13
Show Gist options
  • Select an option

  • Save tenkunkyab/ae828175e2d23ce31dbd to your computer and use it in GitHub Desktop.

Select an option

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 ]
<?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