title: PHP If an Hour Is Between Two Other Hours
body: <p>I need to work out if the current hour is between two other times. For example to check if the time is between 07:00 and 10:00 I could use:</p>
  
  <pre><code>$currentTime = new DateTime('09:00');
  $startTime = new DateTime('07:00');
  $endTime = new DateTime('10:00');
  
  if ($currentTime-&gt;format('H:i') &gt;= $startTime-&gt;format('H:i') &amp;&amp; $currentTime-&gt;format('H:i') &lt;= $endTime-&gt;format('H:i')) {
      // Do something
  }
  </code></pre>
  
  <p>The problem I have is what happens if the time is 01:00 and I want to check if it's between 22:00 and 07:00. I'm not bothered that that it is another day, just if it falls between those two hours on a 24hr clock. Example 01:00 is between 22:00 and 07:00 </p>
  
  <p>22:00, 23:00, 00:00, <strong>01:00</strong>, 02:00... 07:00</p>
  
  <p>What I'm trying to achieve in the end is different prices can be set for a service between different times. So I currently loop through each hour working out what price bracket that hour falls into and the changing the price accordingly. If anyone has a more elegant solution for the problem I would be grateful to learn.</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>Say I have a rule that says between 10pm and 7am I want to charge double. I loop through each hour from the start time to the end time and check if each hour falls between 22:00 (10pm) and 07:00 (7am) and if so it should be charged double. I want to avoid having to take in to account the date.</p>