Hey,
I’m trying to setup a code that will display certain messages depending on what time of day it is… like, “Good Morning” if it’s in the morning, and so forth…
Any suggestions?
- johnny
This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.
The active forums are here.
July 11, 2007 10:53am
Subscribe [3]#1 / Jul 11, 2007 10:53am
Hey,
I’m trying to setup a code that will display certain messages depending on what time of day it is… like, “Good Morning” if it’s in the morning, and so forth…
Any suggestions?
- johnny
#2 / Jul 11, 2007 11:10am
That would be relatively easy with a bit of PHP code if based on the server time. Take the current time stamp, limit that only to the hour (0-24) and use a few if-statements. Would be possible with a plugin as well.
However, something like this often makes me feel stupid: Servers in the US are greeting me as a European user with a totally inappropriate message. Using the IP address of the visitor to determine the country and then a hopefully more or less meaningful time zone on which the output would be based is (of cause) a much more complicated task. For logged in users, you can as well use their time zone settings - but most likely not everyone visiting the site will be logged in.
#3 / Jul 11, 2007 11:12am
cool…. do you know where i can get this code?
#4 / Jul 11, 2007 11:41am
Something like this?
<?php $hour = date("H");
if ($hour < 12) {
echo "Good morning";
}
elseif ($hour < 17) {
echo "Good afternoon";
}
else {
echo "Good evening";
} ?>No ... I don’t think I know where to get something like this 😉
Don’t forget to enable PHP for that template.
#5 / Jul 11, 2007 11:43am
Maybe this plugin will help you to get going? (Unless I’m totally misunderstanding what you’re trying to do here…)
Edit: Excuse my brain fart. I did misread…
#6 / Jul 11, 2007 12:33pm
If it’s only for some welcome message stuff you could also just use some javascript, like this.
That uses the current time of the user’s computer so you don’t run into the problems Markus described.