title: MySQL / PHP - Find available time slots
body: <p>There have been a few questions asked on similar topics but I cannot find a solution to this specific problem and would be thankful for your input.</p>
  
  <p>I am working on a booking engine where users can book certain services online. I am stuck on finding and displaying available time slots within a specific day (or week). I know the length of the needed time slot (eg. 1 hour) and the business hours in which time slots are bookable (eg. 09:00h - 18:00h). Additionally I have a MySQL table that stores the already existing appointments. The columns relevant to my questions look like this:</p>
  
  <pre><code>id  start (datetime)        end (datetime)
  1   '2012-11-16 13:00:00'   '2012-11-16 14:30:00'
  2   '2012-11-16 15:00:00'   '2012-11-16 16:00:00'
  3   '2012-11-17 12:00:00'   '2012-11-16 15:45:00'
  4   '2012-11-17 13:00:00'   '2012-11-16 16:15:00'
  ...
  </code></pre>
  
  <p>Now given the information mentioned above, I am unable to find a good solution (in MySQL or PHP) for retrieving a list of available time slots. There is one more condition: Time slots can only start in quarterly steps. Ie. for the example data above on the 16th available one hour time slots would be:<br/>
  09:00, 09:15, 09:30, 09:45, 10:00, ..., 12:00, 16:00, 16:15, ..., 17:00.<br/>
  <br/>
  Please note that even though there may be overlapping times (as in sample data) an available time slot cannot overlap.<br/>
  <br/>What would you think is the best way to approach this? </p>