douting0585 2018-04-17 03:36
浏览 16
已采纳

如何从结束日期开始-1天

<p>Closing on <span>{{ $event->endDate->format('d/m/Y') }}</span></p>

Now my current result is Closing on 13/1/2017.

The result I request for is Closing on 12/1/2017.

how to -1 day from it?

  • 写回答

2条回答 默认 最新

  • dqluw20882 2018-04-17 03:40
    关注
    <?php
    echo date('d-m-Y',strtotime('-1 day', strtotime(date('13-01-2017'))));
    

    Use strtotime, it support this -1day notation.

    or datetime oop way

    echo (new DateTime('13-01-2017'))->sub(new DateInterval('P1D'))->format('d-m-Y') ;
    

    In your case,

    echo (new DateTime($event->endDate->format('d-m-Y')))->sub(new DateInterval('P1D'))->format('d/m/Y') ;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 有没有帮写代码做实验仿真的
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥30 vmware exsi重置后登不上
  • ¥15 易盾点选的cb参数怎么解啊
  • ¥15 MATLAB运行显示错误,如何解决?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?