ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Good morning, good evening...

July 11, 2007 10:53am

Subscribe [3]
  • #1 / Jul 11, 2007 10:53am

    Johnny Walker

    29 posts

    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

    ms

    274 posts

    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

    Johnny Walker

    29 posts

    cool…. do you know where i can get this code?

  • #4 / Jul 11, 2007 11:41am

    ms

    274 posts

    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

    Lanitha

    13 posts

    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

    silenz

    1651 posts

    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.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases