How to count the days without saturday and sunday for a month

前端 未结 3 1788
南方客
南方客 2020-12-22 06:23

I am using this to find the total number of days in a month dynamically

$count = cal_days_in_month(CAL_GREGORIAN, $_POST[\'PayMonth\'], $_POST[\'PayYear\']);         


        
3条回答
  •  再見小時候
    2020-12-22 06:46

    This is what I use to calculate the number of days without weekend in a month:

    $nbdayinmonth = cal_days_in_month(CAL_GREGORIAN, $_POST['PayMonth'], $_POST['PayYear']);
    
    $nbday = 0;
    for ($i = 1; $i <= $nbdayinmonth; $i++) {
        $weekday = (int)date("w", strtotime($i . "-" . $_POST['PayMonth'] . "-" . $_POST['PayYear']));
        if ($weekday > 0 && $weekday < 6)
            $nbday++;
    }
    echo $nbday;
    

提交回复
热议问题