Hi I am collecting the month and the year from a form and want to generate an array of the number of dates on that particular month seperated by weeks assuming sunday
as the beginning of week.
For example, if the input is month=January
and year=2018
, the desired result is
$array_of_dates =Array ( [Week 1] => '01/01/2018',.....,'06/01/2018'
[Week 2] => '07/01/2018',.....,'13/01/2018'
[Week 3] => '14/01/2018',.....,'20/01/2018'
[Week 4] => '21/01/2018',.....,'27/01/2018'
[Week 5] => '28/01/2018',.....,'31/01/2018' )
I tried this
function weeks_in_month($month, $year) {
$start = mktime(0, 0, 0, $month, 1, $year);
$end = mktime(0, 0, 0, $month, date('t', $start), $year);
$start_week = date('W', $start);
$end_week = date('W', $end);
if ($end_week < $start_week) { // Month wraps
return ((52 + $end_week) - $start_week) + 1;
}
return ($end_week - $start_week) + 1;
}
But this only gives me the number of weeks for that month.