php function for get all mondays within date range

Rather than get all days and loop through them all, get the first Monday after the start date and then iterate 7 days at a time:

$endDate = strtotime($endDate);
for($i = strtotime('Monday', strtotime($startDate)); $i <= $endDate; $i = strtotime('+1 week', $i))
    echo date('l Y-m-d', $i);

Leave a Comment