Partioning time into time blocks with PHP; issues with rationalizing current block
<p>There is probably a much easier way to do this. Given my novice level of skill with PHP, I imagine there are some grievous errors with how I'm constructing this. I humbly accept any criticism, as I'm just starting out, and would be glad to learn better practices.</p>

<p>However, I'm trying to partition time into two-hour time blocks. The code is commented in accordance with each block, but I'd like it to say one is within the "4:00 PM to 6:00 PM" time block if it's currently 5:30 PM.</p>

<p>I'm not entirely certain how I would structure the if statement to properly select the time. I figure a more experienced set of eyes may be able to point out a solution. The currently included if statements do not work, but are included merely as an example.</p>

<p>This is obviously part of a greater script, but I'm pretty certain the issue lies within the following code. However, I can include the entire script if necessary.</p>

<pre><code>&lt;?php

date_default_timezone_set('America/Chicago'); // Set default time zone
$currenttime = date("G"); // Set the time in 24 hour format, no leading zeroes

if (0 &gt;= $currenttime &amp;&amp; $currenttime &lt; 8) {
    $thisblock="00:00:00"; // Overnights
}

if (8 &gt;= $currenttime &amp;&amp; $currenttime &lt; 10) {
    $thisblock="08:00:00"; // Eight to ten.
}

if (10 &gt;= $currenttime &amp;&amp; $currenttime &lt; 12) {
    $thisblock="10:00:00"; // Ten to noon.
}

if (12 &gt;= $currenttime &amp;&amp; $currenttime &lt; 14) {
    $thisblock="12:00:00"; // Noon to 2:00 PM.
}

if (14 &gt;= $currenttime &amp;&amp; $currenttime &lt; 16) {
    $thisblock="14:00:00"; // 2:00 PM to 4:00 PM
}

if (16 &gt;= $currenttime &amp;&amp; $currenttime &lt; 18) {
    $thisblock="16:00:00"; // 4:00 PM to 6:00 PM
}

if (18 &gt;= $currenttime &amp;&amp; $currenttime &lt; 20) {
    $thisblock="18:00:00"; // 6:00 PM to 8:00 PM
}

if (20 &gt;= $currenttime &amp;&amp; $currenttime &lt; 22) {
    $thisblock="20:00:00"; // 8:00 PM to 10:00 PM
}

if (22 &gt;= $currenttime &amp;&amp; $currenttime &lt; 24) { 
    $currentblock="22:00:00"; // 10:00 PM to midnight
}

?&gt;
</code></pre>
