php count days excluding weekends

41

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));
}

Comments

Submit
0 Comments