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

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

你可能感兴趣的:(日期)