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?
3184 次
2 に答える
8
あなたは時間を忘れた
$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;
この出力:
Array
(
[0] => Array
(
[eventID] =>
[date] => 2012-02-28
[max] =>
)
[1] => Array
(
[eventID] =>
[date] => 2012-02-29
[max] =>
)
)
時間がない場合は、次のようになります。
Array
(
[0] => Array
(
[eventID] =>
[date] => 2012-02-28
[max] =>
)
)
于 2012-02-27T20:39:23.847 に答える
0
L - うるう年かどうか
于 2012-02-27T20:38:28.527 に答える