dongyi7901 2019-01-22 08:55
浏览 8
已采纳

如何打印2个日期之间的所有日期

I'm sure if it possible so I consult with you.

I have 2 string that contain dates: d/m/Y

for instant:

$from_date= "17/10/2018";

$till_date = "20/10/2018";

is it possible to print the total number of day between those dates and also to print the dates?

For instant:

4 days

17/10/2018

18/10/2018

19/10/2018

20/10/2018
  • 写回答

4条回答 默认 最新

  • douzhuan1432 2019-01-22 08:59
    关注

    This should work:

    $start = new DateTime('2018-10-17');
    $end = new DateTime('2018-10-20');
    
    while ($start <= $end) {
        echo $start->format('Y-m-d') . '<br>';
        $start->modify('+1 day');
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?