문제

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] => 
        )

)

다른 팁

php.net quote

L - Whether it's a leap year

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top