php - 计算一个月的工作天数

标签 php date datetime

<分区>

Possible Duplicate:
Get number of weekdays in a given month

如何计算任意一个月的工作日? cal_days_in_month 仅返回一个月中的总天数。我的任务是计算除星期六和星期日或仅星期日外的一个月中的天数。有什么方法可以找到这个?

最佳答案

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 是星期六。

关于php - 计算一个月的工作天数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14185975/

相关文章:

php - PhpMyAdmin 中的登录屏幕

PHP 在 while 循环中求和一个值,但有条件

r - 转换为日期格式错误: character string is not in a standard unambiguous format

java - 月份不是从日期打印的 - Java DateFormat

java - LocalDateTime 时区有效,而 LocalTime 无效

php - 阻止用户查看页面超过 3 次

javascript - 将excel DATEVALUE转换为javascript日期

php - 有没有办法根据日期倒计时 4 周(一周一周)? PHP/MySQL

java - 如何减去两次写成 hh :mm and display the result in a textview

mysql - 使用 php5-fpm 、Nginx、APC、Mysql 对 magento 进行内存调整