According to formula https://en.wikipedia.org/wiki/ISO_week_date in the Weeks per year section you should be able to find each year with 53 weeks. I have copied the formula into PHP but it seems to mess up around 2020 returning 52 weeks instead of 53.
function weeks($year){
$w = 52;
$p = ($year+($year/4)-($year/100)+($year/400))%7;
if ($p == 4 || ($p-1) == 3){
$w++;
}
return $w." ".$p;
}
for ($i = 2000; $i <= 2144; $i++) {
echo $i." (".weeks($i).") | ";
}
From Wikipedia
The following 71 years in a 400-year cycle have 53 weeks (371 days); years not listed have 52 weeks (364 days); add 2000 for current years:
004, 009, 015, 020, 026, 032, 037, 043, 048, 054, 060, 065, 071, 076, 082, 088, 093, 099, 105, 111, 116, 122, 128, 133, 139, 144
I know I can grab the total amount of weeks for a given year using the date() function but I'm just wondering if anyone knows the math since the formula on wikipedia seems to be wrong.
EDIT WORKING CODE
function p($year){
return ($year+floor($year/4)-floor($year/100)+floor($year/400))%7;
}
function weeks($year){
$w = 52;
if (p($year) == 4 || p($year-1) == 3){
$w++;
}
return $w; // returns the number of weeks in that year
}
for ($i = 2000; $i <= 2144; $i++) {
echo $i." (".weeks($i).") | ";
}