PHP Time, greater and less than.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
randall
Forum Newbie
Posts: 16
Joined: Fri May 08, 2009 9:01 pm

PHP Time, greater and less than.

Post 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"; 
}
?>
Last edited by Benjamin on Fri May 08, 2009 9:31 pm, edited 1 time in total.
Reason: Changed code type from text to php.
mdk999
Forum Newbie
Posts: 22
Joined: Fri May 08, 2009 3:21 pm

Re: PHP Time, greater and less than.

Post 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";
 
 
Last edited by Benjamin on Fri May 08, 2009 10:20 pm, edited 1 time in total.
Reason: Changed code type from text to php.
randall
Forum Newbie
Posts: 16
Joined: Fri May 08, 2009 9:01 pm

Re: PHP Time, greater and less than.

Post by randall »

Worked! Thank you very much.
Post Reply