php count days excluding weekends

Solutions on MaxInterview for php count days excluding weekends by the best coders in the world

showing results for - "php count days excluding weekends"
Maryjane
10 Oct 2019
1function sumDays($days = 0, $format = 'd/m/Y') {
2    $incrementing = $days > 0;
3    $days         = abs($days);
4    $actualDate   = date('Y-m-d');
5
6    while ($days > 0) {
7        $tsDate    = strtotime($actualDate . ' ' . ($incrementing ? '+' : '-') . ' 1 days');
8        $actualDate = date('Y-m-d', $tsDate);
9
10        if (date('N', $tsDate) < 6) {
11            $days--;
12        }
13    }
14
15    return date($format, strtotime($actualDate));
16}
17