$alldays = intval((sstrtotime($_POST['dayb']) - sstrtotime($_POST['daya'])) / 3600 / 24) + 1; //总天数
$weeks = intval($alldays / 7); //纯周数
$mdays = $alldays - 7 * $weeks; //除了纯周数外,余下那周的天数
if($mdays == '0') {
$_POST['psdays'] = 5 * $weeks;
$_POST['zmdays'] = 2 * $weeks;
} else {
$aday = ''; //第一天是星期几,后面算出来
$adays = date("D", sstrtotime($_POST['daya']));
if($adays == 'Mon') {
$aday = "1";
} elseif($adays == 'Tue') {
$aday = "2";
} elseif($adays == 'Wed') {
$aday = "3";
} elseif($adays == 'Thu') {
$aday = "4";
} elseif($adays == 'Fri') {
$aday = "5";
} elseif($adays == 'Sat') {
$aday = "6";
} else {
$aday = "7";
}
if($aday == '7') {
$_POST['zmdays'] = 1 + 2 * $weeks;
$_POST['psdays'] = $mdays - 1 + 5 * $weeks;
} else {
$nfanwei = 7 - $aday; //范围,从星期$aday开始(包含这一天),还有$nfanwei天就到周六
if($mdays > $nfanwei) {
$_POST['zmdays'] = 2 + 2 * $weeks;
$_POST['psdays'] = $mdays - 2 + 5 * $weeks;
} elseif($mdays == $nfanwei) {
$_POST['zmdays'] = 1 + 2 * $weeks;
$_POST['psdays'] = $mdays - 1 + 5 * $weeks;
} else {
$_POST['zmdays'] = 0 + 2 * $weeks;
$_POST['psdays'] = $mdays + 5 * $weeks;
}
}
}
原文地址:http://www.corange.cn/archives/2011/08/3781.html