21
Probier mal so:
$free_intervals = array();
$next_start = new DateTime('now');
while ($next_start) {
$row = mysql_fetch_array($result);
$start = $next_start;
if (! empty($row['Anreise']) && ! empty($row['Abreise'])) {
$end = new DateTime($row['Anreise']);
$next_start = new DateTime($row['Abreise']);
} else {
$end = new DateTime('now');
$end->add(new DateInterval('P360D'));
$next_start = false;
}
if ($end < $start) {
continue;
}
$interval = $end->diff($start);
if ($interval->format('%a') <= 3) {
continue;
}
$free_intervals[] = array(
'start' => $start->format('d.m.Y'),
'end' => $end->format('d.m.Y')
);
if (count($free_intervals) >=6) {
break;
}
}