【问题标题】:I can not return the final date of a range of dates [duplicate]我无法返回一系列日期的最终日期[重复]
【发布时间】:2019-07-10 15:32:41
【问题描述】:

使用此代码,我可以获取开始日期,但不能获取结束日期

$period = new \DatePeriod(new \DateTime($dateStart), new \DateInterval('P1D'), (new \DateTime($dateend)));

我返回了一个日期范围,但我没有取最后一个日期,在这个例子中我用了 2 天,我取了第一个但不是第二个,应该是 2019-08-05

DatePeriod {#448 ▼
  period: every + 1d, from 2019-08-04 00:00:00.0 (included) to 2019-08-05 00:00:00.0
  +"start": DateTime @1564876800 {#468 ▼
    date: 2019-08-04 00:00:00.0 UTC (+00:00)
  }
  +"current": null
  +"end": DateTime @1564963200 {#457 ▶}
  +"interval": DateInterval {#458 ▶}
  +"recurrences": 1
  +"include_start_date": true
}

如何包含结束日期?

【问题讨论】:

    标签: php laravel function date controller


    【解决方案1】:

    我通过在最后一天增加 1 天解决了这个问题

    $dateend->modify('+1 day');
    $period = new \DatePeriod(new \DateTime($dateStart), new \DateInterval('P1D'), (new \DateTime($dateend)));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-12-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多