Jump to content

Checking the time


bschultz

Recommended Posts

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!

 

Link to comment
Share on other sites

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'

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.