PHP 计算两个日期之间是否有周六周日

PHP 两个日期之间是否有周六周日

目标:两个日期之间如果存在周六周日,有几个周六周日就延长几天

1.两个日期之间有多少个周六周日
2.截止日期加上统计出来的天数

注:两个日期为时间戳
记录一下

 public function weektimes()
    {
        $start_time = time();//当前日期时间戳
        $endstime = $start_time + 86400 * 7;//当前日期往后7天
        //是否有周六周日
         $week_array = [7, 1, 2, 3, 4, 5, 6];
         $i = 0;
         while ($start_time <= $endstime) {
             $now_time = date('Y-m-d', $start_time);
             // 可根据自己想要的返回格式进行调整
             $alltime[$i]['week'] = $week_array[date("w", strtotime($now_time))];
             $start_time = strtotime('+1 day', $start_time);
             $i++;
         }
         $list = [];
         foreach ($alltime as $key => $value) {
         		//周六周日数组
             if ($value['week'] >= 6) {
                 $list[] = $value['week'];
             }
         }
         //周六周日有几天
         if (count($list) > 0) {
             $count = count($list) - 1;
             $endtime = $endstime + 86400 * $count;
         } else {
             $endtime = $endstime;
         }
         
       return $endtime;
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值