Search code examples
phpcalendardaysweekdayweekend

Get number of weekdays in a given month


I want to calculate the number of weekdays days in a give month and year. Weekdays means monday to friday. How do i do it ?


Solution

  • Some basic code:

    $month = 12;
    $weekdays = array();
    $d = 1;
    
    do {
        $mk = mktime(0, 0, 0, $month, $d, date("Y"));
        @$weekdays[date("w", $mk)]++;
        $d++;
    } while (date("m", $mk) == $month);
    
    print_r($weekdays);
    

    Remove the @ if your PHP error warning doesn't show notices.