php获取之前五天的工作日

使用日期时,会有特定需求,如果想选取五个工作日,需要判断每天是不是工作日,代码等一下解释:

$selectdate=array();
        $checkdate=array();
        $forshowdate = array();
        $showdate = array();
        $checkdate["7"] = date("Y-m-d",strtotime("-0 day"));
        $checkdate["6"] = date("Y-m-d",strtotime("-1 day"));
        $checkdate["5"] = date("Y-m-d",strtotime("-2 day"));
        $checkdate["4"] = date("Y-m-d",strtotime("-3 day"));
        $checkdate["3"] = date("Y-m-d",strtotime("-4 day"));
        $checkdate["2"] = date("Y-m-d",strtotime("-5 day"));
        $checkdate["1"] = date("Y-m-d",strtotime("-6 day"));
       /* var_dump( $checkdate["7"]);*/
        for ($i=1;$i<=7;$i++){
            if((date('w',strtotime($checkdate[$i]))==6) || (date('w',strtotime($checkdate[$i])) == 0)){

                /*echo $i.'你输入的日期是周末'."</br>";
                var_dump($checkdate[$i]);
                echo "</br>";*/
                $uuu = 3;
            }else{
                /*echo $i.'当然也不是周末了'."</br>";
                var_dump($checkdate[$i]);
                echo "</br>";*/
                array_push($selectdate,$checkdate[$i]);
            }
        }

        $data["selectdate"] = $selectdate;

strtotime选择是哪天,选择时首先选取七天,无论如何,七天中都有五天工作日(你要是说放假我就不理你了,这里不考虑放假时间),遍历一下数组,如果数组中的数据不是周末就将数据放到另一个数组中,否则可以不执行操作。最后查看在新数组中的数据。

猜你喜欢

转载自blog.csdn.net/King_flag/article/details/53996209