如何计算没有星期六和星期日一个月的日子 [英] How to count the days without saturday and sunday for a month

查看:149
本文介绍了如何计算没有星期六和星期日一个月的日子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用它来动态地查找一个月的总天数

I am using this to find the total number of days in a month dynamically

$count = cal_days_in_month(CAL_GREGORIAN, $_POST['PayMonth'], $_POST['PayYear']);



但如何计算该月份离开周六和周日的天数?

But How can i calculate the number of days in that particular month leaving Saturday and Sunday ?

推荐答案

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



参考: link1 LINK2

这篇关于如何计算没有星期六和星期日一个月的日子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆