bschultz Posted December 19, 2011 Share Posted December 19, 2011 I need to query a database for a starting time for a meeting, and if the start time is at 7pm, I need to allow access to a page from 6pm til 11pm. Not a problem. The problem lies when the ending time (4 hours after the start time) crosses over to a new day. Here's what I have: <?php elseif ($row['meeting'] == "7:00pm") { $starthour = 18; $endhour = 23; } elseif ($row['meeting'] == "8:00pm") { $starthour = 19; $endhour = 0; } if ($thishour <= $endhour && $thishour >= $starthour) { include "meeting_ok.php"; } else { echo "Meeting room is unavailable at this time...."; } ?> The "0" for endhour is throwing things off. How should I best account for a new day? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/253460-checking-the-time/ Share on other sites More sharing options...
scootstah Posted December 19, 2011 Share Posted December 19, 2011 Convert it to UNIX timestamps and then compare it. $start = strtotime('22:00'); $end = strtotime('+4 hours', $start); Now, $end is 4 hours after $start - which accounts for days. Quote Link to comment https://forums.phpfreaks.com/topic/253460-checking-the-time/#findComment-1299213 Share on other sites More sharing options...
bschultz Posted December 19, 2011 Author Share Posted December 19, 2011 Thanks...that worked! Quote Link to comment https://forums.phpfreaks.com/topic/253460-checking-the-time/#findComment-1299223 Share on other sites More sharing options...
xyph Posted December 19, 2011 Share Posted December 19, 2011 Assuming $time is the starting time, in the MySQL datetime format (YYYY-MM-DD HH:MM:SS) SELECT `date` FROM `table` WHERE DATE_SUB(NOW(), INTERVAL 1 HOUR) <= '$time' AND DATE_ADD(NOW(), INTERVAL 3 HOUR) >= '$time' Quote Link to comment https://forums.phpfreaks.com/topic/253460-checking-the-time/#findComment-1299229 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.