Calculate business days

后端 未结 30 1824
猫巷女王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:10

    $startDate = new DateTime( '2013-04-01' );    //intialize start date
    $endDate = new DateTime( '2013-04-30' );    //initialize end date
    $holiday = array('2013-04-11','2013-04-25');  //this is assumed list of holiday
    $interval = new DateInterval('P1D');    // set the interval as 1 day
    $daterange = new DatePeriod($startDate, $interval ,$endDate);
    foreach($daterange as $date){
    if($date->format("N") <6 AND !in_array($date->format("Y-m-d"),$holiday))
    $result[] = $date->format("Y-m-d");
    }
    echo "
    ";print_r($result);
    

提交回复
热议问题