paolo@bimodesign.com | +34 608 61 64 10

Framework

        

Loop into a period

This function return all the days of a period (from PHP 5.3)
The two dates of the period, have to this format:

StartDay: 2013-08-01
EndDay: 2013-08-28

//
// Loop to get all day of the period
//
$beginPeriod = new DateTime($startDay);
$endPeriod   = new DateTime($endDay);

// adding one day to the end, for the loop
$endPeriod   = $endPeriod->modify('+1 day'); 

$numDayToLoop = DateInterval::createFromDateString('1 day');
$period = new DatePeriod($beginPeriod, $numDayToLoop, $endPeriod);

foreach ( $period as $eventDay )
  echo $eventDay->format( "l Y-m-d H:i:s\n" );