<p> 现在还有问题</p><p> 周一,周二不能做节假日</p><p> 可能算法上还有问题,等待你的更新...</p><p> /**</p><p> * sports98</p><p> * flyruns@hotmail.com (欢迎交流)</p><p> */</p><p> ================</p><p> <code><html><br /><head><br /><title>计算工作日(计算一年内)</title><br /></head><br /><style type="text/css"><br />
body,td {font-size:12px}<br /></style><br /><body><br /><form action="<?=$_SERVER[PHP_SELF]?>" method="post" name="form1"><br /><table cellpadding=0 cellspacing=0 border=0><br /> <tr><td colspan=2 height=30 align=center>工作日计算器(计算一年内)<br /> <tr><td>开始日期:<td><input type="text" name="starttime" value="<?=date("Y")?>-01-01"><br /> <tr><td>结束日期:<td><input type="text" name="endtime" value="<?=date("Y-m-d")?>"><br /> <tr><td>周休息数:<td><input type="text" size=1 name="rest" value="2">天 始休日:<br /> <select name="restday"><br /> <option value="1">星期一</option><br /> <option value="2">星期二</option><br /> <option value="3">星期三</option><br /> <option value="4">星期四</option><br /> <option value="5">星期五</option><br /> <option value="6" selected>星期六</option><br /> <option value="7">星期七</option><br /> </select><br /> <tr><td valign=top>法定假期:<td><br /> <textarea name="ordainrest" rows=7>05-01&5<br />10-01&5</textarea>(&进行分隔)<br /> <tr><td>缺席天数:<td><input type="text" size=1 name="absent" value="0">天(请假等未工作日)<br /> <tr><td>加班天数:<td><input type="text" size=1 name="overtime" value="0">天<br /> <tr><td>补假天数:<td><input type="text" size=1 name="supplytime" value="0">天<br /> <input type="submit" value="计算数据"><br /></table><br /></form><br /><?php<br />if(is_array($_POST)){//有POST数据<br />
$starttime=date("z",mktime(0,0,0,substr($_POST[starttime],5,2),substr($_POST[starttime],8,2),substr($_POST[starttime],0,4)));<br />
$endtime=date("z",mktime(0,0,0,substr($_POST[endtime],5,2),substr($_POST[endtime],8,2),substr($_POST[endtime],0,4)));<br />
$alltime=$endtime-$starttime+1;<br />
echo "自开始日期到结束日期,共:".$alltime."天";<br />
echo "<br>缺席天数:".$_POST[absent]."天";<br />
echo "<br>加班日期:".$_POST[overtime]."天";<br />
echo "<br>补假日期:".$_POST[supplytime]."天";<br />
echo "<br>法定假期:<br>";<br />
$tmpa=explode("\n",$_POST[ordainrest]);<br />
for($Tmpb=0;$Tmpb<count($tmpa);$Tmpb++){<br />
$tmpc=explode("&",$tmpa[$Tmpb]);<br />
echo " ".$tmpc[0]." 休息 ".$tmpc[1]." 天<br>";<br />
$tmpsize=date("z",mktime(0,0,0,substr($tmpc[0],0,2),substr($tmpc[0],3,2),date("Y")));//节假日的日期数据<br />
if($tmpsize>=$starttime && $tmpsize<=$endtime){<br />
$alltime=$alltime-$tmpc[1];//从总的工作日中去掉法定日期<br />
}<br />
}<br />//调试点  <br />// echo "<h3>$starttime $endtime</h3>";<br />
$alltime-=$_POST[absent];//扣除缺席天数<br />
$alltime+=$_POST[overtime];//加上加班日期<br />
$alltime-=$_POST[supplytime];//去掉补充的假期<br />
//计算周休息日<br />
$fweek=date("w",mktime(0,0,0,substr($_POST[starttime],5,2),substr($_POST[starttime],8,2),substr($_POST[starttime],0,4)));//获得开始日期的周数<br />
$eweek=date("w",mktime(0,0,0,substr($_POST[endtime],5,2),substr($_POST[endtime],8,2),substr($_POST[endtime],0,4)));//结束周数<br />
//这里要判断一下开始的星期天数(要求获得第一周的日期数)<br />
if($fweek<$_POST[restday]){//不是休息日(指定的工作休息日),在指定休息日前<br />
$ctmp=abs($_POST[restday]-$fweek);<br />
$runday=date("d",mktime(0,0,0,substr($_POST[starttime],5,2),$ctmp+substr($_POST[starttime],8,2),substr($_POST[starttime],0,4)));<br />
//获得第一周的日期<br />
}else{//再指定休息日后(e.g. $fwwk=6 $_POST[restday]=2)<br />
$ctmp=abs($fweek-$_POST[restday]);<br />
$runday=date("d",mktime(0,0,0,substr($_POST[starttime],5,2),$ctmp+substr($_POST[starttime],8,2),substr($_POST[starttime],0,4)));<br />
}<br />//调试点  <br />// echo "<h3>$runday $ctmp $_POST[restday] $fweek</h3>";<br />
for($ttmpa=0;;$ttmpa++){<br />
//将当前的节假日向后推7日,进行判断 最终$ttmpa为节假日数<br />
$cday=date("z",mktime(0,0,0,substr($_POST[starttime],5,2),$runday+7*$ttmpa,substr($_POST[starttime],0,4)));<br />
if($cday>$endtime){<br />
break;<br />
}<br />
}<br />
echo "<br>开始日期:".date("Y-m-d 星期w",mktime(0,0,0,substr($_POST[starttime],5,2),substr($_POST[starttime],8,2),substr($_POST[starttime],0,4)));;<br />
echo "<br>结束日期:".date("Y-m-d 星期w",mktime(0,0,0,substr($_POST[endtime],5,2),substr($_POST[endtime],8,2),substr($_POST[endtime],0,4)));;<br />
echo "<br>共计周末休息:".$ttmpa."×".$_POST[rest]."=".$ttmpa*$_POST[rest]."天<span onclick=\"if(document.all['allweek'].style.display==''){this.innerHTML='(+)';document.all['allweek'].style.display='none';}else{this.innerHTML='(-)';document.all['allweek'].style.display='';}\" style=\"cursor:hand\">(+)</span>";<br />
echo "<div id=\"allweek\" style=\"display:'none'\">";<br />
for($TTmpa=0;$TTmpa<$ttmpa;$TTmpa++){<br />
$dday=date("Y-m-d 星期w",mktime(0,0,0,substr($_POST[starttime],5,2),$runday+7*$TTmpa,substr($_POST[starttime],0,4)));<br />
echo "$dday<br>";<br />
}<br />
echo "</div>";<br />
if($fweek==6){//周六<br />
}else if($fweek==0){//周日,则总休息日仅仅去一天休息日<br />
$alltime+=1;//增加一天<br />
}<br />
$allcday=$ttmpa*$_POST[rest];//总的工作休息日<br />
$alltime-=$allcday;<br />
echo "<hr size=1>有效的工作日:<font color=red>$alltime</font>";<br />}<br />?><br /></body><br /></html></code></p>