【发布时间】:2011-01-05 00:13:36
【问题描述】:
我正在尝试使用 PHP 计算给定日期范围内的工作日数(周一至周五)。如果用户输入开始 (2010-12-01) 和结束日期 (2010-12-24),该函数应输出该日期范围内的工作日数。
这是我发现的,但没有帮助..
function getworkingdays_time($STARTSTAMP, $ENDSTAMP){
$noofdays = ceil(($ENDSTAMP - $STARTSTAMP) / 86400);
$sundaycounter = 0;
$saturdaycounter = 0;
$holidaycounter = 0;
$offset = 0;
$holidaycounter = check_holiday_range($STARTSTAMP, $ENDSTAMP); // check holiday range
if(!defined("WORKSATURDAYS"))
{
define("WORKSATURDAYS", 0);
}
if(!defined("WORKSUNDAYS"))
{
define("WORKSUNDAYS", 0);
}
for ($i = 0; $i <= $noofdays; $i++){
$ts = $STARTSTAMP + ($i * 86400);
if (WORKSATURDAYS == '0' && date("l", $ts) == "Saturday"){
## they dont work saturdays
$saturdaycounter ++;
} elseif (WORKSUNDAYS == '0' && date("l", $ts) == "Sunday"){
## they dont work sundays
$sundaycounter ++;
}
}
$total = $holidaycounter + $saturdaycounter + $sundaycounter;
$offset = $total;
if ($total > 0){
$total = getworkingdays_time($ENDSTAMP + 86400, ($ENDSTAMP + ($total * 86400) + 86400));
$offset += $total;
}
unset($holidaycounter, $saturdaycounter, $sundaycounter, $i, $noofdays, $ts, $total);
return ($offset);
}
任何帮助将不胜感激。 非常感谢 PSi
【问题讨论】:
标签: php