PHP calculating number of days between 2 dates

前端 未结 4 556
野的像风
野的像风 2021-01-03 02:31

I am developing a web application which revolves around dates.

I need to calculate numbers based around days elasped, for example - pseudo code

$coun         


        
4条回答
  •  天涯浪人
    2021-01-03 03:01

    You could create a loop which goes to the next day in the $count_only array, from the $start_date and stopping (returning from the function) upon reaching the $end_date.

    function number_of_days_between($start_date, $finish_date, $count_only) {
        $count  = 0;
        $start  = new DateTime("@$start_date");
        $end    = new DateTime("@$finish_date");
        $days   = new InfiniteIterator(new ArrayIterator($count_only));
        foreach ($days as $day) {
            $count++;
            $start->modify("next $day");
            if ($start > $end) {
                return $count;
            }
        }
    }
    

提交回复
热议问题