200字范文,内容丰富有趣,生活中的好帮手!
200字范文 > php工作日 计算工作日(jessie看)-PHP教程 PHP应用

php工作日 计算工作日(jessie看)-PHP教程 PHP应用

时间:2023-10-23 06:55:55

相关推荐

php工作日 计算工作日(jessie看)-PHP教程 PHP应用

现在还有问题

周一,周二不能做节假日

可能算法上还有问题,等待你的更新…

/**

* sports98

* flyruns@ (欢迎交流)

*/

================

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

body,td {font-size:12px}

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<=$endtime){

$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";

}

?>

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。