PHP - get last week number in year

Viewed 36829

Tell me please how to get the last number of weeks in a year?

6 Answers

With strtotime() you can count till 2037 cause the 2038 bug

To be sure to count all weeks of a year you must count from the 28th December, because is the only day surely in the last week of the year.

<?php
for($year=2018;$year<2038;$year++) {
    echo $year.' => ' .date("W",strtotime('28th December '.$year)) .' Weeks<br>';
}
?>

Result:

  • 2018 => 52 Weeks
  • 2019 => 52 Weeks
  • 2020 => 53 Weeks
  • 2021 => 52 Weeks
  • 2022 => 52 Weeks
  • 2023 => 52 Weeks
  • 2024 => 52 Weeks
  • 2025 => 52 Weeks
  • 2026 => 53 Weeks
  • 2027 => 52 Weeks
  • 2028 => 52 Weeks
  • 2029 => 52 Weeks
  • 2030 => 52 Weeks
  • 2031 => 52 Weeks
  • 2032 => 53 Weeks
  • 2033 => 52 Weeks
  • 2034 => 52 Weeks
  • 2035 => 52 Weeks
  • 2036 => 52 Weeks
  • 2037 => 53 Weeks
Related