Ad Code

Calculate number of working days in a month

function countDays($year, $month, $ignore) {
    $count = 0;
    $counter = mktime(0, 0, 0, $month, 1, $year);
    while (date("n", $counter) == $month) {
        if (in_array(date("w", $counter), $ignore) == false) {
            $count++;
        }
        $counter = strtotime("+1 day", $counter);
    }
    return $count;
}
echo countDays(2013, 1, array(0, 6)); // 23

The date function is used in this example. Note about ignore parameter: 0 is sunday, ..., 6 is saturday.

 


 

Post a Comment

0 Comments