Page 1 of 1

PHP Time, greater and less than.

Posted: Fri May 08, 2009 9:18 pm
by randall
I am trying to write a small function that will display different messages for different times of the day. I want to let people know that phone lines are open between 8:00AM and 6:00PM then closed the rest of the day.

The message I want to see would be something like this:

Our time is: 04:34 PM
Phone Lines are Open


Here is my code and the Greater and Less than is giving me problems... the time is changing, but the message is not.

Code: Select all

<?php
$time_offset ="0"; // Change this to your time zone
$time_a = ($time_offset * 120);
$time = date("h:i A",time() + $time_a);
$opentime = date("Hi");
echo 'Our time is: '.$time;
 
if ($opentime > 0800) { 
echo "<br>Phone Lines are Open"; 
}
else if ($opentime < 1800) { 
echo "<br>Phone Lines are Open"; 
}
else { 
echo "<br>Phone Lines are Closed"; 
}
?>

Re: PHP Time, greater and less than.

Posted: Fri May 08, 2009 9:46 pm
by mdk999
For me it would make more sense to convert all to unixtime and then test to see if the current time falls in my range .. but you could do ..

Code: Select all

 
 
if ($opentime > 0800  && $opentime < 1800) {
echo "<br>Phone Lines are Open";
}
else echo "<br>Phone Lines are Closed";
 
 

Re: PHP Time, greater and less than.

Posted: Fri May 08, 2009 9:57 pm
by randall
Worked! Thank you very much.