After doing some research into Dateperiod, it turns out it by default excludes the enddate, even though it doesn't explicitly state that anywhere in the PHP manual. I also didn't notice any option for including it. The only option there seems to be is the option to exclude the start date. Has anyone else run across this?
you forgot the time
$start_date = '02/28/2012 00:00:00';
$end_date = '02/29/2012 23:59:59';
$intrDate = '1D';
$start = new \DateTime($start_date);
$end = new \DateTime($end_date);
$interval = new \DateInterval('P'.$intrDate);
$period = new \DatePeriod($start, $interval, $end);
print_r($start_date);
print_r($end_date);
print_r($period);
foreach ($period as $day) {
$dates[] = array(
'eventID' => $event_id,
'date' => $day->format('Y-m-d'),
'max' => $data['numAttending']);
}
print_r($dates);
exit;
this output:
Array
(
[0] => Array
(
[eventID] =>
[date] => 2012-02-28
[max] =>
)
[1] => Array
(
[eventID] =>
[date] => 2012-02-29
[max] =>
)
)
without the time, you will get:
Array
(
[0] => Array
(
[eventID] =>
[date] => 2012-02-28
[max] =>
)
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With