I am currently generating an html table which contains dates in it's header
Those dates are the supposedly first days of each week through the whole year (the displayed year may change according to a filter), and they are generated by the following code
<?php $firstDay = strtotime($year . 'W' . str_pad($week, 2, '0', STR_PAD_LEFT)); ?>
<td><?= date('d/m/Y', $firstDay) ?></td>
This is inside a for
loop that makes the $week
go from 1
to the number of weeks in the whole year.
What I have noticed is that for some years, the last monday of December from the previous year is included in there too, such as 29/12/2014
when I select 2015
in the filter.
So far, to determine the number of weeks that are in a month, I used to count the number of mondays in said month programmatically and used it as the colspan for the row above the dates row, and so, there are uncounted weeks for january for some years, which makes the table shift.
The rendered html for the year 2015
would look like this
<table>
<thead>
<tr>
<th colspan="4">January</th>
<th colspan="4">February</th>
[...]
</tr>
<tr>
<!-- Under January cell -->
<th>29/12/2014</th>
<th>05/01/2015</th>
<th>12/01/2015</th>
<th>19/01/2015</th>
<!-- Under February cell -->
<th>26/01/2015</th>
<th>02/02/2015</th>
[...]
</tr>
</thead>
[...]
And after searching and testing a lot of week per month counters, none of those that I found seem to include that last monday from the previous year.
Could anyone find out how to count the weeks including that extra week from the previous year when it occurs?