title: Second Saturday of Month Function in PHP
body: <p>I found this PHP code <a href="http://linuxmafia.com/pipermail/sf-lug/2006q1/000114.html" rel="nofollow">credit to creator</a> and want to implement it a different way:</p>
  
  <p>The goal is to have the code automatically adjust the following statement to be the second Saturday of every month from now until eternity:</p>
  
  <p><hr>
  Next membership meeting: Saturday, <strong>MONTH, DAY, YEAR</strong>, 11 a.m. to noon.</p>
  
  <p>As in: "Saturday, <strong>February 12, 2011</strong>, 11 a.m. to noon."</p>
  
  <hr>
  
  <p>I am no PHP guru, can someone kindly edit it to work?</p>
  
  <pre><code>&lt;?php
  
       function nextMeeting($nextMonth = false) {
  
       $day=date("j");
       $month=date("n");
       $year=date("Y");
  
       if ($nextMonth) {
               $day=1;
               if ($month == 12) {
                       $month=1;
                       $year++;
               } else {
                       $month++;
               }
       }
  
       $dayofweek=date("w");
       $firstOfMonth=date("w",mktime(0, 0, 0, $month , 1, $year ));
  
  
       // figure out what date is the second Saturday of the month
       if ( $firstOfMonth &gt; 0 ) {
               $firstSunday= 8 - $firstOfMonth;
       } else {
               $firstSunday= 1;
       }
  
       $firstSundayDate=date("D",mktime(0, 0, 0, $month ,  
       $firstSunday, $year));
  
       // figure out what date the third monday of the month is
       if ( $firstOfMonth &gt; 1) {
               $offSet = 8 - $firstOfMonth;
       } elseif ( $firstOfMonth == 0 ) {
               $offSet=1;
       } else {
               $offSet=0;
       }
       $thirdMonday= 15 + $offSet;
       $thirdMondayDate=date("D",mktime(0, 0, 0, $month ,  
       $thirdMonday, $year));
  
       // lets see which of these dates now applies
       if ($day &lt;= $firstSunday) {
               // we didn't miss the first meeting
               $nextMeeting=$firstSunday;
               $nextMeetingDate=mktime(0, 0, 0, $month ,  
               $nextMeeting, $year);
       } elseif ( ($day &gt; $firstSunday) &amp;&amp; ($day &lt;= $thirdMonday) ) {
               // we missed the first meeting of the month, but can still make the second
               $nextMeeting=$thirdMonday;
               $nextMeetingDate=mktime(0, 0, 0, $month ,  
               $nextMeeting, $year);
       } else {
               // we need to wait until next month
               $nextMeetingDate=nextMeeting(1);
               $nextMeeting=nextMeeting(1);
       }
  
       return $nextMeetingDate;
  
       }
  
       $meeting=nextMeeting();
  
       echo "Next membership meeting is on " . date('l dS \of F Y', $meeting);
  
       ?&gt;
  </code></pre>