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
https://forums.phpfreaks.com/topic/219450-checking-if-time-is-between-two-values/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.