title: Detect overlapping time ranges in PHP
body: <p><a href="https://i.stack.imgur.com/nx19g.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nx19g.png" alt="enter image description here"></a></p>
  
  <p>I want to see if time ranges overlap, if they do, true should be returned, otherwise false. If I have selected this time range:</p>
  
  <blockquote>
    <p><strong>10:30:00 - 11:30:00</strong> </p>
  </blockquote>
  
  <p>then I need to check if it doesn't overlap another time range. For example:</p>
  
  <blockquote>
    <p><strong>10:30:00 - 11:30:00</strong> overlaps with <strong>10:30:00 - 12:30:00</strong> so I have to disable the slot but I don't know how to do the comparison correctly. </p>
  </blockquote>
  
  <p>I have the following function, but I think it doesn't work as I want it to work.</p>
  
  <pre><code>  $as = $selectedSlot['slot_start'];
    $ae = $selectedSlot['slot_end'];
    $bs = $DB_slots['slot_start'];
    $be = $DB_slots['slot_end'];
  
  
  function checkSlotRange($as,$ae,$bs,$be){
    $as = strtotime($as);
    $ae = strtotime($ae);
    $bs = strtotime($bs);
    $be = strtotime($be);
    if($as &lt;= $bs &amp;&amp; $ae &lt;= $be){
      return true;
    }else{
    return false;
    }  
  }
  </code></pre>