A solution found is as follows:
function get_weekend_days($start_date, $end_date, $weekend_days=1) {
$data = array();
$start_reduce = $end_add = 0;
$start_N = date("N",strtotime($start_date));
$start_reduce = ($start_N == 7) ? 1 : 0;
$end_N = date("N",strtotime($end_date));
//
$weekend_days = intval($weekend_days);
switch ($weekend_days)
{
case 2:
in_array($end_N,array(6,7)) && $end_add = ($end_N == 7) ? 2 : 1;
break;
case 1:
default:
$end_add = ($end_N == 7) ? 1 : 0;
break;
}
$days = ((strtotime($end_date) - strtotime($start_date))/86400) + 1;
$data["total_days"] = $days;
$data["total_relax"] = floor(($days + $start_N - 1 - $end_N) / 7) * $weekend_days - $start_reduce + $end_add;
return $data;
}
Why is this $data ["total_relax"] calculated this way? This method doesn"t seem to work very well. For example, today is Sunday, but the returned $data ["total_relax"] is 0
.