I am trying to calculate the difference between two dates by excluding Saturday and Sunday. The output should be 9 but i got 1 instead.
<?php
$date1= mktime(0, 0, 0, 12, 20, 2011);
$date2= mktime(0, 0, 0, 12, 30, 2011);
$day1= date("D",$date1);
$day2= date("D",$date2);
$i=0;
while ($date1<=$date2)
{
if ($day1 != "Sat" || $day2 !="Sat" || $day1开发者_运维技巧 != "Sun" || $day2 !="Sun")
{
$i++;
}
else
{
$i+0;
}
$date1=array(date("Y",$date1), date("n",$date1), date("d",$date1)+1);
}
$diff=$i;
echo $diff;
?>
Seems as if the condition in your if statement is giving the problem.
if ($day1 != "Sat" && $day2 !="Sat" && $day1 != "Sun" && $day2 !="Sun")
{
$i++;
}
else
{
$i+0;
}
Switching || to &&.
精彩评论