Re: [PHP] greeting based on time

2002-09-03 Thread Bas Jobsen

?
$hour=date('H');
switch(true)
{
case ($hour 12):   echo 'Good Morning';break;
case ($hour 18):   echo 'Good Afternoon';  break;
default:echo 'Good Night';  break;
}
?


Op dinsdag 03 september 2002 13:01, schreef Javier Montserat:
 really simple one -

 does someone have a bit of code that will variously display 'good morning',
 'good afternoon', 'good evening' based on the current time?

 good morning from london,

 Javier



 _
 Send and receive Hotmail on your mobile device: http://mobile.msn.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] greeting based on time

2002-09-03 Thread Justin French

Ummm, current time where? :)

Assuming you mean your server's time, it shouldn't be too hard, but i
thought I'd point out that your readers/users are bound to be in different
time zones.  Whilst some may think oh, different time zone, others will
probably think idiots :)

Then another option would be to do it based on the user's time, but if they
have their clock wrong, same problem.

Anyhoo, I just whipped this up... there is probably 100's of ways of doing
it, but this was the first off the top of my head.  Untested code.  Returns
good evening from 5:00pm  11:59pm, good morning from 12 midnight until
11:59am, and good afternoon from 12 midday thru to 4.59pm.  I haven't
taken into account daylight savings, timezones or anything else... just real
basic, based on the hours.

?
function serverTimeGreeting()
{
$h = date('G');   // current hour (0-23)
$greeting = good evening;
if($h  17)
{ $greeting = good afternoon; }
if($h  12)
{ $greeting = good morning; }
return $greeting;
}

echo serverTimeGreeting();

?

Justin



on 03/09/02 9:01 PM, Javier Montserat ([EMAIL PROTECTED]) wrote:

 really simple one -
 
 does someone have a bit of code that will variously display 'good morning',
 'good afternoon', 'good evening' based on the current time?
 
 good morning from london,
 
 Javier


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php