Get number of weekdays in a given month

后端 未结 12 2202
无人及你
无人及你 2020-12-03 15:56

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 ?

12条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-03 16:23

    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.

提交回复
热议问题