Calculate business days

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

    For holidays, make an array of days in some format that date() can produce. Example:

    // I know, these aren't holidays
    $holidays = array(
        'Jan 2',
        'Feb 3',
        'Mar 5',
        'Apr 7',
        // ...
    );
    

    Then use the in_array() and date() functions to check if the timestamp represents a holiday:

    $day_of_year = date('M j', $timestamp);
    $is_holiday = in_array($day_of_year, $holidays);
    

提交回复
热议问题