$startday=strtotime('2008-01-10');
$endday=strtotime('2008-02-27');
$step=3600*24;
$singleday=0;
$doubleday=0;
for ($i=$startday;$i<=$endday;$i=$i+$step)
{
if (fmod(date("d",$i),2))
{
$singleday++;
}
else
{
$doubleday++;
}
}
echo "单号:$singleday,双号:$doubleday\n";

解决方案 »

  1.   


    function countdate($start,$end,$type=1){
    $start = strtotime($start);
    $end = strtotime($end);
    $day = 60*60*24;
    $start += $day;
    $i = 0;
    for($start; $start < $end; $start += $day){
    if((date('j',$start)%2 != 0 ? 1 : 0) === $type ){
    $i++;
    }
    }
    return $i;
    }
    echo countdate('2008-02-20','2008-03-10');
      

  2.   

    $sday= strtotime('2008-01-10');
    $eday= strtotime('2008-02-27');
    $step = 3600*24;
    $s_ct = 0;
    $d_ct = 0;
    for($i=$sday; $i <= $eday; $i += $step){
        date("d",$i)%=2?$s_ct++:$d_ct++
    }
    echo "单日:".$s_ct.",双日:".$d_ct