Re: greeting based on time

From: Date: Tue, 03 Sep 2002 13:41:00 +0000
Subject: Re: greeting based on time
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-115026@lists.php.net to get a copy of this message
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 (codareef@hotmail.com) 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

« previous php.general (#115026) next »