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

前端 未结 3 1756
南方客
南方客 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:40

    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
    

    Reference : link1 and link2

提交回复
热议问题