title: Finding every nth X-day of the month using PHP, will it always be correct?
body: <p>OK, I've put together some code which, in this particular case, finds the second (2nd) Sunday of every month depending on whether or not you're before or after it (specifically at 5:00PM that day).</p>
  
  <pre><code>&lt;?php
      $count = 0;
      for( $i = 1 ; $i &lt;=30 ; $i++ )//30 is much more than is needed
      {
          $date = date_create_from_format('Y-m-d H:i:s',date('Y-m-').$i.' 17:00:00');
          if( $date-&gt;format('D') == 'Sun' )
          {
              $count++;
          }
          if( $count == 2 )
          {
              break;
          }
      }
      $count = 0;
      if( date('Y-m-d H:i:s') &gt; $date-&gt;format('Y-m-d H:i:s') )
      {
          for( $i = 1 ; $i &lt;=30 ; $i++ )
          {
              $date = date_create_from_format('Y-m-d H:i:s',date('Y-').(string)(((int)date('n')+1)%12).'-'.$i.' 17:00:00');
              if( $date-&gt;format('D') == 'Sun' )
              {
                  $count++;
              }
              if( $count == 2 )
              {
                  break;
              }
          }
          echo $date-&gt;format('F jS, Y');
      }
      else
      {
          echo $date-&gt;format('F jS, Y');
      }
  ?&gt;
  </code></pre>
  
  <p>So if you are at the green star it will display August 14, and if you're at the blue star it will display September 11:</p>
  
  <p><a href="https://i.stack.imgur.com/sRJf0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/sRJf0.png" alt="enter image description here"></a></p>
  
  <p>My question is will this always be correct indefinitely?</p>