title: Calculating last week of the year in PHP to skip to next year
body: <p>I am creating a schedule based on weeks. Now i've come to the problem that 2020 is an odd year and like week 53.</p>
  <p>Now i want to go from the last week of the year to the first week.
  I've tried some but couldn't get it to work (from 53th week to 1st)</p>
  <pre><code>&lt;header&gt;
    &lt;?
    $week_start = new DateTime();
    $week_start-&gt;setISODate($year,$weeknr);
    $weeknr = $week_start-&gt;format('W');
  
    $week_start2 = new DateTime();
    $week_start2-&gt;setISODate($year,$weeknr);
    $yearnum = $week_start2-&gt;format('Y');
  
    $weekmin = $weeknr - 1;
  
  
    $date = strtotime(&quot;31 December $year&quot;);
    $last_week = gmdate(&quot;W&quot;, $date);
  
    if($last_week == 53 &amp;&amp; $weeknr == 53){
      $weekplus = $weeknr - 51;
      $yearnum++;
    }else{
      $weekplus = $weeknr + 1;
    }
  
    echo'&lt;a href=&quot;./agenda_user?wknr='.$weekmin.'&quot;&gt;&lt;/a&gt;';?&gt;
    &lt;span&gt;Week &lt;?
  
    echo $weeknr.' ';
  
  
    echo $yearnum;
  
  
    ?&gt;&lt;/span&gt;
    &lt;? echo '&lt;a href=&quot;./agenda_user?wknr='.$weekplus.'&quot;&gt;&lt;/a&gt;';?&gt;
  &lt;/header&gt;
  </code></pre>
  <p>I've found this answer
  <a href="https://stackoverflow.com/a/3319413/11608455">https://stackoverflow.com/a/3319413/11608455</a>
  but this doesnt fully answer my question</p>