- print_r: documentation ( source)
- explode: documentation ( source)
- next: documentation ( source)
- current: documentation ( source)
- iterator_to_array: documentation ( source)
<?php
$dateRange = '2014-01-01 - 2014-01-08';
$parts = explode(' - ', $dateRange);
$begin = new \DateTime($parts[0]);
$end = new \DateTime($parts[1]);
$interval = new \DateInterval('P1D');
$datePeriod = new \DatePeriod($begin, $interval, $end);
$periodArray = iterator_to_array($datePeriod);
/*$startDate = reset($periodArray);
$endDate = end($periodArray);*/
$startDate = current($datePeriod);
while($date = next($datePeriod)) {
$endDate = $date;
}
#echo $datePeriod->start->format('c');
#echo "\n";
echo $startDate->format('c');
echo "\n";
#echo "\n";
#echo $datePeriod->end->format('c');
#echo "\n";
echo $endDate->format('c');
echo "\n";
echo "\n";
echo print_r($periodArray);