Calculate business days

后端 未结 30 1864
猫巷女王i
猫巷女王i 2020-11-22 05:16

I need a method for adding \"business days\" in PHP. For example, Friday 12/5 + 3 business days = Wednesday 12/10.

At a minimum I need the code to understand weekend

30条回答
  •  灰色年华
    2020-11-22 06:15

    I had this same need i started with bobbin's first example and ended up with this

      function add_business_days($startdate,$buisnessdays,$holidays=array(),$dateformat){
        $enddate = strtotime($startdate);
        $day = date('N',$enddate);
        while($buisnessdays > 1){
            $enddate = strtotime(date('Y-m-d',$enddate).' +1 day');
            $day = date('N',$enddate);
            if($day < 6 && !in_array($enddate,$holidays))$buisnessdays--;
        }
        return date($dateformat,$enddate);
      }
    

    hth someone

提交回复
热议问题