php 任意时间区间,计算工作日

 strtotime($end_date)) list($start_date, $end_date) = array($end_date, $start_date);
 
    $start_reduce = $end_add = 0;
    $start_N      = date('N',strtotime($start_date));
    $start_reduce = ($start_N == 7) ? 1 : 0;
 
    $end_N = date('N',strtotime($end_date));
 
    // 进行单、双休判断,默认按单休计算
    $weekend_days = intval($weekend_days);
    switch ($weekend_days)
    {
        case 2:
            in_array($end_N,array(6,7)) && $end_add = ($end_N == 7) ? 2 : 1;
            break;
        case 1:
        default:
            $end_add = ($end_N == 7) ? 1 : 0;
            break;
    }
    
    $days = round(abs(strtotime($end_date) - strtotime($start_date))/86400) + 1;
    $data['total_days'] = $days;
    $data['total_relax'] = floor(($days + $start_N - 1 - $end_N) / 7) * $weekend_days - $start_reduce + $en

你可能感兴趣的:(php)