Home > php教程 > php手册 > 计算工作日(jessie看)

计算工作日(jessie看)

WBOY
Release: 2016-06-21 09:11:53
Original
1577 people have browsed it

现在还有问题
周一,周二不能做节假日
可能算法上还有问题,等待你的更新...
/**
  * sports98
  * flyruns@hotmail.com (欢迎交流)
  */
================


计算工作日(计算一年内)





    
工作日计算器(计算一年内)
    
开始日期: -01-01">
    
结束日期: ">
    
周休息数: 天 始休日:
    
    
法定假期:
    (&进行分隔)
    
缺席天数: 天(请假等未工作日)
    
加班天数:
    
补假天数:
    


if(is_array($_POST)){//有POST数据
    $starttime=date("z",mktime(0,0,0,substr($_POST[starttime],5,2),substr($_POST[starttime],8,2),substr($_POST[starttime],0,4)));
    $endtime=date("z",mktime(0,0,0,substr($_POST[endtime],5,2),substr($_POST[endtime],8,2),substr($_POST[endtime],0,4)));
    $alltime=$endtime-$starttime+1;
    echo "自开始日期到结束日期,共:".$alltime."天";
    echo "
缺席天数:".$_POST[absent]."天";
    echo "
加班日期:".$_POST[overtime]."天";
    echo "
补假日期:".$_POST[supplytime]."天";
    echo "
法定假期:
";
    $tmpa=explode("\n",$_POST[ordainrest]);
        for($Tmpb=0;$Tmpb            $tmpc=explode("&",$tmpa[$Tmpb]);
            echo "          ".$tmpc[0]." 休息 ".$tmpc[1]." 天
";
            $tmpsize=date("z",mktime(0,0,0,substr($tmpc[0],0,2),substr($tmpc[0],3,2),date("Y")));//节假日的日期数据
            if($tmpsize>=$starttime && $tmpsize                $alltime=$alltime-$tmpc[1];//从总的工作日中去掉法定日期
            }
        }
//调试点    
//    echo "

$starttime $endtime

";

    $alltime-=$_POST[absent];//扣除缺席天数
    $alltime+=$_POST[overtime];//加上加班日期
    $alltime-=$_POST[supplytime];//去掉补充的假期

    //计算周休息日
    $fweek=date("w",mktime(0,0,0,substr($_POST[starttime],5,2),substr($_POST[starttime],8,2),substr($_POST[starttime],0,4)));//获得开始日期的周数
    $eweek=date("w",mktime(0,0,0,substr($_POST[endtime],5,2),substr($_POST[endtime],8,2),substr($_POST[endtime],0,4)));//结束周数
    //这里要判断一下开始的星期天数(要求获得第一周的日期数)
    if($fweek        $ctmp=abs($_POST[restday]-$fweek);
        $runday=date("d",mktime(0,0,0,substr($_POST[starttime],5,2),$ctmp+substr($_POST[starttime],8,2),substr($_POST[starttime],0,4)));
        //获得第一周的日期
    }else{//再指定休息日后(e.g. $fwwk=6 $_POST[restday]=2)
        $ctmp=abs($fweek-$_POST[restday]);
        $runday=date("d",mktime(0,0,0,substr($_POST[starttime],5,2),$ctmp+substr($_POST[starttime],8,2),substr($_POST[starttime],0,4)));
    }
//调试点    
//    echo "

$runday $ctmp $_POST[restday] $fweek

";
    for($ttmpa=0;;$ttmpa++){
        //将当前的节假日向后推7日,进行判断  最终$ttmpa为节假日数
        $cday=date("z",mktime(0,0,0,substr($_POST[starttime],5,2),$runday+7*$ttmpa,substr($_POST[starttime],0,4)));
        if($cday>$endtime){
            break;
        }
    }
    echo "
开始日期:".date("Y-m-d 星期w",mktime(0,0,0,substr($_POST[starttime],5,2),substr($_POST[starttime],8,2),substr($_POST[starttime],0,4)));;
    echo "
结束日期:".date("Y-m-d 星期w",mktime(0,0,0,substr($_POST[endtime],5,2),substr($_POST[endtime],8,2),substr($_POST[endtime],0,4)));;
    echo "
共计周末休息:".$ttmpa."×".$_POST[rest]."=".$ttmpa*$_POST[rest]."天(+)";
    echo "
";
    for($TTmpa=0;$TTmpa        $dday=date("Y-m-d 星期w",mktime(0,0,0,substr($_POST[starttime],5,2),$runday+7*$TTmpa,substr($_POST[starttime],0,4)));
        echo "$dday
";
    }
    echo "
";
    if($fweek==6){//周六
    }else if($fweek==0){//周日,则总休息日仅仅去一天休息日
        $alltime+=1;//增加一天
    }
    $allcday=$ttmpa*$_POST[rest];//总的工作休息日
    $alltime-=$allcday;
    echo "
有效的工作日:$alltime";
}
?>




Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template