首页 > php教程 > php手册 > 2014年工作日计算(去除法定假日和周六日,但包括调休日)

2014年工作日计算(去除法定假日和周六日,但包括调休日)

WBOY
发布: 2016-06-06 19:34:35
原创
1529 人浏览过

PHP,每年运行一次,每次需要配置指定,当前年,法定假日,调休日 无 ?php$year = '2014';function addYear($date){ return $GLOBALS['year'].'-'.$date;}function getWorkDays($startDate,$endDate,$publicHolidays,$holidayTune){ $workDays = array(); whi

PHP,每年运行一次,每次需要配置指定,当前年,法定假日,调休日
<?php

$year = '2014';

function addYear($date)
{
    return $GLOBALS['year'].'-'.$date;
}

function getWorkDays($startDate,$endDate,$publicHolidays,$holidayTune)
{
    $workDays = array();
    while(1){
        $day = date('Y-n-j', $startDate);
        if(!in_array($day,$publicHolidays))
        {
            $workDays[] = $day;
        }
        $startDate += 86400;
        if($startDate>=$endDate){break;}
    }
    foreach($workDays as $k=>$date)
    {
        $info = getdate(strtotime($date));
        if(in_array($info['weekday'],array('Sunday','Saturday')) and !in_array($date,$holidayTune))
        {
            unset($workDays[$k]);
        }
    }
    return $workDays;
}
// define the public holidays
$publicHolidays =  array('1-1','1-31','2-1','2-2','2-3','2-4','2-5','2-6','4-5','4-6','4-7','5-1','5-2','5-3','5-31','6-1','6-2','9-6','9-7','9-8','10-1','10-2','10-3','10-4','10-5','10-6','10-7');
$publicHolidays = array_map('addYear',$publicHolidays);


// define the holiday tune.
$holidayTune = array('1-26','2-8','5-4','9-28','10-11');
$holidayTune = array_map('addYear',$holidayTune);


// initialize starting date and the ending date.
$startDate = strtotime($year.'-1-1');
$endDate = strtotime('+1 Year', $startDate);
$workDays = getWorkDays($startDate,$endDate,$publicHolidays,$holidayTune);
echo json_encode($workDays);
登录后复制
相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门推荐
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板