Get number of weekdays in a given month

后端 未结 12 2205
无人及你
无人及你 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:24

    Find the last day and the weekday for the given month
    then do a simple while loop like :-

    $dates = explode(',', date('t,N', strtotime('2013-11-01')));
    $day = $dates[1]; 
    $tot = $dates[0]; 
    $cnt = 0;
    while ($tot>1)
    {   
        if ($day < 6)
        {   
            $cnt++;
        }   
        if ($day == 1)
        {   
            $day = 7;
        }   
        else
        {   
            $day--;
        }   
        $tot--;
    }
    

    $cnt = total of weekday (Monday to Friday) for a given month

提交回复
热议问题