Caveat: this is totally untested! And it only counts Saturdays and Sundays, not any of the other processing you show.
$dfromconvert = explode("-",$dfrom);//esplode la data [Giorno-mese-anno]
$dtoconvert = explode("-",$dto);//esplode la data [Giorno-mese-anno]
$dfrommktime = mktime(0,0,0,$dfromconvert[1],$dfromconvert[0],$dfromconvert[2]);//riassembla la data esplosa!
$dtomktime = mktime(0,0,0,$dtoconvert[1],$dtoconvert[0],$dtoconvert[2]);//riassembla la data esplosa!
//Caveat: This is totally untested!
/
Find out how many seven-day intervals there are between $dfrommktime to
$dtomktime.
/
$intervaldays=intval(($dtomktime-$dfrommktime)/86400); //Number of days
$intervalweeks=intval($intervaldays/7); //Number of whole weeks
$intervalremainder=$intervaldays%7; //Remainder
/
How many seven-day periods were there? That times 2 is the number of weekends Sat, Sun. The important thing to note is that this figure is the same no
matter when we start counting the period from!
/
$weekends=$intervalweeks*2;
/ This is the tricky bit. We need to know the day of the week we're starting on and ending
on. The interval from Sunday to Tuesday contains one weekend day;
Saturday to Monday contains two; Saturday to Saturday contains one;
Monday to Wednesday doesn't contain any; Wednesday to Monday contains
two; Saturday to Sunday and Sunday to Saturday both contain two.
/
$f=date('w',$dfrommktime);
$t=date('w',$dtomktime);
if($f!=0 && $l!=6)
{
$weekends += ($l>$f) ? 2 : 0;
}
else
{
$weekends += ($f==0 && $l==6) ? 2 : 1;
}