title: PHP - calculating the number of weeks between two dates
body: <p>I'm trying to calculate the number of weeks between two dates. The code below has a result of 3 weeks. However, it is really 4 weeks. Why is it calculating incorrectly and what is the solution?</p>
  
  <p>I'm curious to know why this specific code isn't working but would also like to know if there is a better way of doing it.</p>
  
  <p>I'm running PHP version 7.2. Below is the code I'm using:</p>
  
  <pre><code>$HowManyWeeks = date( 'W', strtotime( 2019-04-21 23:59:00 ) ) - date( 'W', strtotime( 2019-03-25 00:00:00 ) );
  </code></pre>
  
  <p>The value of $HowManyWeeks should be 4 but it is displaying as 3. </p>
  
  <p>Also, when I try that code at <a href="https://phpfiddle.org/" rel="nofollow noreferrer">https://phpfiddle.org/</a> it gives an error of:</p>
  
  <pre><code>Line : 2 -- syntax error, unexpected '23' (T_LNUMBER), expecting ',' or ')'
  </code></pre>
  
  <p>But it displays '3' without any error when running it on my server.</p>
  
  <p>Thanks,</p>
  
  <p>Tim</p>