Need to find total hours splitting the hours for the weekend which is Friday, Saturday and Sunday and other weekdays. Using the following piece of code but it's not yielding the desired result.
$start_day = date('w', $start_time);
$start_hour = date('G', $start_time);
$end_day = date('w', $end_time);
$end_hour = date('G', $end_time);
$normal_hours = $surge_hours = 0;
for (;($start_hour < 24 && $start_day <= $end_day); $start_hour++) {
switch ($start_day) {
case 0: $surge_hours++;
break;
case 5: $surge_hours++;
break;
case 6: $surge_hours++;
break;
case 1: $normal_hours++;
break;
case 2: $normal_hours++;
break;
case 3: $normal_hours++;
break;
case 4: $normal_hours++;
break;
}
echo __line__;
echo "<pre>";
print_r('surgehours'.$surge_hours);
echo "<br/>";
print_r('normalhours'.$normal_hours);
echo "<pre/>";
if ($start_hour == 23) {
$start_hour = 0;
$start_day++;
}
if ($start_day == $end_day) {
if ($start_hour == $end_hour)
break;
}
}
Failing Uses cases:
If the start day is Friday, i.e.: 29 July and end day is 1 August ( $start_day = 5 and $end_day = 1
)
It does not go into the loop.
Any ideas how to calculate the hours?