计算一个月的工作天数 [英] Calculate number of working days in a month
本文介绍了计算一个月的工作天数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:
获取给定月份的工作日数
如何计算任何月份的工作日? cal_days_in_month
只返回一个月内的总天数。我的任务是计算除星期六,星期日或星期日以外的月份天数。任何方法找到这个?
How to calculate working days of any month? cal_days_in_month
returns simply the total number of days in a month. My task is to calculate number of days in month except Saturdays and Sundays or Sundays alone. Any method to find this?
推荐答案
function countDays($year, $month, $ignore) {
$count = 0;
$counter = mktime(0, 0, 0, $month, 1, $year);
while (date("n", $counter) == $month) {
if (in_array(date("w", $counter), $ignore) == false) {
$count++;
}
$counter = strtotime("+1 day", $counter);
}
return $count;
}
echo countDays(2013, 1, array(0, 6)); // 23
date
函数。关于忽略参数的注意事项:0是星期日,...,6是星期六。
The date
function is used in this example. Note about ignore parameter: 0 is sunday, ..., 6 is saturday.
这篇关于计算一个月的工作天数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文