title: How do I find a available date in mysql for date intervals?
body: <p><strong>Problem</strong></p>
  
  <p>I have a php class booking script which allows the booking of class at recurrences of every 1 - 4 week for a year.</p>
  
  <p>Classes are either 30 or 60 minute durations.  </p>
  
  <p>If a new class is booked in a time slot it checks to see if there is a clashing class at that time of the day selected.</p>
  
  <p>The script at the moment can find clashes for weekly recurrences however I haven't been able to work out how to check the recurrences of every 2 weeks+.</p>
  
  <p>Some code</p>
  
  <pre><code>$datetime = '2015-01-13 09:00:00';
  </code></pre>
  
  <p>The SQL looks like this. (Might be suboptimal) </p>
  
  <pre><code> $sql = "SELECT  datetime
          FROM    classes
          WHERE   (staff_id = :staff_id AND DAYOFWEEK(datetime) = DAYOFWEEK(:datetime))
          AND (TIME(datetime) &gt;= TIME(:time_from) AND TIME(datetime) &lt; TIME(:time_to))
          OR (TIME(:datetime_from) BETWEEN TIME(datetime) 
              AND TIME(ADDTIME(datetime_to, '-0 0:0:1')))";
  </code></pre>
  
  <p>If the count is > 0 then it won't allow a class to be booked at that time/day chosen for the whole year.</p>
  
  <p><strong>Desired ability</strong></p>
  
  <p>If there is a fortnightly class booked at say Tuesday 9am stating at 2015-01-13 09:00:00 I need to be able to use the vacancy on alternating weeks.  At the moment this blocks out every Tuesday.</p>
  
  <p>I have created an array of the recurrence dates and compared that to the results from the above SQL but those results are the dates which clash.</p>
  
  <p>Any ideas?</p>