<?php function weeks_in_month($month, $year) { $dates = []; $week = 1; $date = new DateTime("$year-$month-01"); $days = (int)$date->format('t'); // total number of days in the month $oneDay = new DateInterval('P1D'); for ($day = 1; $day <= $days; $day++) { $dates["Week $week"] []= $date->format('d/m/Y'); $dayOfWeek = $date->format('l'); if ($dayOfWeek === 'Saturday') { $week++; } $date->add($oneDay); } return $dates; } print_r(weeks_in_month(1, 2018));
You have javascript disabled. You will not be able to edit any code.