title: Check if current time is between two times, with the possibility of lapping days
body: <p>I have a system that accepts user submissions, and upon receiving a submission the system will go through all timeslots to find the appropriate timeslot. The problem is that it needs to be able to check against the start &amp; end times if the end time laps to the next day.</p>
  
  <p>Take the following example:
  A timeslot begins at 10:30 PM on the current day and ends at 4:00 PM the next day. If the current time is between 10:30 PM and 11:59:59 PM, the submission will be assigned to that timeslot. However, if the current time is between 12:00 AM and 4:00 PM then it will skip the timeslot.</p>
  
  <p>This is what I have so far:</p>
  
  <pre><code>function check_time($from, $to, $time) {
      $time = strtotime($time);
      $from = strtotime($from);
      $to_ = strtotime($to);
      $to = $to_ &lt;= $from ? strtotime($to . " tomorrow") : $to_;
      return ($time &gt;= $from &amp;&amp; $time &lt;= $to);
  }
  
  $timeslots = array(
      array("16:00:00", "22:30:00"),
      array("22:30:00", "16:00:00")
  );
  foreach ($timeslots as $slot) {
      if (check_time($slot[0], $slot[1], date("H:i:s")))
          {
              echo "true\n";
          }
      else 
          {
              echo "false\n";     
          }
  }
  </code></pre>
  
  <p>If the current time is 23:00:00, then the result would be</p>
  
  <pre><code>false
  true
  </code></pre>
  
  <p>But if the current time is 12:00:00 then the result would be</p>
  
  <pre><code>false
  false
  </code></pre>
  
  <p>even though it's technically between the two times.</p>
  
  <p>I know it has to do with the fact that if it's a new day, then the <code>strtotime</code> result for <code>$from</code> will be later in the day. So instead of checking for 10:30 PM yesterday, it checks for 10:30 PM tonight.</p>
  
  <p>My problem is that I cannot seem to come up with a way to make the <code>$from</code> time switch to the previous day if it needs to, similar to how I force the <code>$to</code> time into the next day.</p>