Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I had two times in the format like 7:30:00 and 22:30:00 stored in the variables $resttimefrom and $resttimeto respectively.

I want to check whether the current time is between these two values. I am checking this with the code

$time = date("G:i:s");
if ($time > $resttimefrom and $time < $resttimeto ){
    $stat = "open";
} else {
    $stat = "close";
} 

But I am always getting the $stat as Close. What may cause that?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
900 views
Welcome To Ask or Share your Answers For Others

1 Answer

you can try using strtotime

$st_time    =   strtotime($resttimefrom);
$end_time   =   strtotime($resttimeto);
$cur_time   =   strtotime(now);

then check

if($st_time < $cur_time && $end_time > $cur_time)
{
   echo "WE ARE CLOSE NOW !!";
}
else{
   echo "WE ARE OPEN  NOW !!";
}

i hope this may help you..


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...