您的位置:首页 > 其它

计算一段日期内的周末天数(星期六,星期日总和

2011-08-29 08:58 274 查看
function get_weekend_days($start_date,$end_date){
if (strtotime($start_date) > strtotime($end_date)) list($start_date, $end_date) = array($end_date, $start_date);
$start_reduce = $end_add = 0;
$start_N = date('N',strtotime($start_date));
$start_reduce = ($start_N == 7) ? 1 : 0;
$end_N = date('N',strtotime($end_date));
in_array($end_N,array(6,7)) && $end_add = ($end_N == 7) ? 2 : 1;
$days = abs(strtotime($end_date) - strtotime($start_date))/86400 + 1;
return floor(($days + $start_N - 1 - $end_N) / 7) * 2 - $start_reduce + $end_add;
}

echo get_weekend_days(date("Y-m-d H:i:s",time()),"2011-8-21 15:23:48");

原文地址:http://www.corange.cn/archives/2011/08/3782.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: