Add X Days To Date, Excluding Weekends

前端 未结 4 1252
渐次进展
渐次进展 2020-12-17 07:01

I\'m currently developing an online subscription application. I\'m having some challenges on the part where the user will select the Number of Days to subscribe and then the

4条回答
  •  借酒劲吻你
    2020-12-17 07:02

    I have developed a new function today that can help people who have this type of problem.

    function sumDays($days = 0, $format = 'd/m/Y') {
        $incrementing = $days > 0;
        $days         = abs($days);
        $actualDate   = date('Y-m-d');
    
        while ($days > 0) {
            $tsDate    = strtotime($actualDate . ' ' . ($incrementing ? '+' : '-') . ' 1 days');
            $actualDate = date('Y-m-d', $tsDate);
    
            if (date('N', $tsDate) < 6) {
                $days--;
            }
        }
    
        return date($format, strtotime($actualDate));
    }
    

提交回复
热议问题