Jump to content

Checking if time is between two values?


Fenhopi

Recommended Posts

Hi!

I have this to check if now is between start time and end time:

 

[date_default_timezone_set('Europe/Belgrade');



$TimeNow = date("H:i" ,time());
$today_date = date('d-m-y');
$GetTimeTable = "SELECT * FROM timetable WHERE username='$username' AND Subject_date='$today_date'";
$ConnectTimeTable = $database->query($GetTimeTable);
$TimeTable = mysql_fetch_array($ConnectTimeTable);

$Subject = $TimeTable['Subject'];

$Start_time = $TimeTable['Start_Time'];
$End_time = $TimeTable['End_Time'];

?><br><?



if($TimeNow >= $Start_time && $TimeNow <= $End_time){
echo "Current Class: ";
echo $Subject;
echo "<br><br>";
// a START time value
$start = $TimeNow;
// an END time value
$end   = $End_time;

// what is the time difference between $end and $start?
if( $diff=@get_time_difference($start, $end) )
{
  echo "Time left: " .
       sprintf( '%02d:%02d', $diff['hours'], $diff['minutes'] );
}
else
{
  echo "Hours: Error";
}



}
else{
echo "No class. ";
}

 

Start time and end time is displayed in the format like 14:26.

 

For some reason this code doesn't work though, I don't get why.

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.