Calculate business days

后端 未结 30 2110
猫巷女王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 05:54

    There are some args for the date() function that should help. If you check date("w") it will give you a number for the day of the week, from 0 for Sunday through 6 for Saturday. So.. maybe something like..

    $busDays = 3;
    $day = date("w");
    if( $day > 2 && $day <= 5 ) { /* if between Wed and Fri */
      $day += 2; /* add 2 more days for weekend */
    }
    $day += $busDays;
    

    This is just a rough example of one possibility..

提交回复
热议问题