0

I am trying to write a script that would collect current time and check if the time falls with a particular time range.

Let say the current time is 12:00am and I want to check if the current time falls within the range of 1 pm to 5 pm. I kind of confuse on how to implement this with php.

3
Contributors
6
Replies
26
Views
4 Years
Discussion Span
Last Post by CodeAngry
0

Well, I'm assuming that this is date independent.

$now = date("His");//or date("H:i:s")
$start = '130000';//or '13:00:00'
$end = '170000';//or '17:00:00'

if($now >= $start && $now <= $end){
    echo "Time in between";
}else{
    echo "Time outside constraints";
}
0

I tried it. But this script does not work for me diafol.

0

It works for me, but you have to check the system time vs. your time. This is sometimes messed up by daylight saving time. You can set your timezone in php.

So just echo $now to see if it matches your time.

0

Time is a relative thing... consider using GMT time.
Also keep in mind that any date, time, datetime can be converted to an integer.
And comparing integers is easy :)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.