Forum Moderators: coopster

Message Too Old, No Replies

time period with php

         

laura2k

8:17 pm on May 11, 2004 (gmt 0)



hi,

can anyone tell me how i can use php to display one thing if the server time is between 18:00-22:00 and all other times it should display something else?

thanx

ergophobe

8:47 pm on May 11, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



$time = date(H);

if ($time <18 ¦¦ $time > 22)
{
display_one_thing();
}
else
{
display_other_thing();
}

laura2k

8:59 pm on May 11, 2004 (gmt 0)



thanx will try that

laura2k

9:06 pm on May 11, 2004 (gmt 0)



i get an error saying:

Parse error: parse error, unexpected T_STRING on the line that reads:

if ($time <18 ¦¦ $time > 22)

any ideas?

also, how about if i want a few different ranges?

e.g.

if time is between 14:00-15:00 display 1, if 15:-18:00 display 2 and if 18:00-22:00 display 3 else display other thing

thanx

ergophobe

9:23 pm on May 11, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You are probably missing a semi-colon, quote or something else like that on the preceding line.

As for additional ranges, it's just the same.

Timotheos

10:04 pm on May 11, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Are you aware that this forum breaks the pipe symbol? So if you copy and paste code from here you have to manually type in your own ¦¦.

laura2k

10:14 pm on May 11, 2004 (gmt 0)



yeah i just figured that out now :) that was the problem anyway thanx for your help

ergophobe

10:31 pm on May 11, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Thanks Timotheos. I always forget about that.

laura2k

7:56 pm on May 12, 2004 (gmt 0)



i am trying to add more time ranges to the following code but cant seem to have any luck:

if ($time <18 ¦¦ $time > 22)
{
echo "time is not between 18:00 - 22:00";
}
else
{
echo "time is between 18:00 - 22:00";
}

i want to add other ranges, such as 13:00-18:00, 22:00-04:00, 04:00-10:00

can anyone please tell me how i can do this?

thanx

jatar_k

8:08 pm on May 12, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



you can either do an if else situation or use a switch. I would use a switch.

<? 
$time = date(H);
switch ($time) {
case ($time < 4):
echo "time is between 00:00 - 04:00";
break;
case ($time < 10):
echo "time is between 04:00 - 10:00";
break;
case ($time < 13):
echo "time is between 10:00 - 13:00";
break;
case ($time < 18):
echo "time is between 13:00 - 18:00";
break;
case ($time < 22):
echo "time is between 18:00 - 22:00";
break;
default:
echo "time is between 22:00 - 24:00";
break;
}
?>

you can always add cases as the need arises