Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Time Greeting

  • This topic is empty.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #29314
    realph
    Participant

    Hey there guys, I’m trying to show a time greeting on my site. The only problem is that I’d like it to display "Good Afternoon" from 12pm onwards, this doesn’t seem to be working. Site link (http://hollandalekane.co.uk/)

    Code used:

    Code:
    Good Evening!

    “; }
    elseif ($hour < 4) { echo "

    Good Evening!

    “; }
    elseif ($hour > 3)
    { echo “

    Good Morning!

    “; }
    }

    elseif ($m == “PM”)
    {
    if ($hour == 12)
    { echo “

    Good Afternoon!

    “; }
    elseif ($hour < 7) { echo "

    Good Afternoon!

    “; }
    elseif ($hour > 6)
    { echo “

    Good Evening!

    “; }
    }
    ?>

    #77504
    MikeC
    Member

    I’ve just had a look at your site and it says ‘Good afternoon’ for me.

    I’m in Spain and it’s 16:35 here, so it seems to be working fine.

    #77813
    realph
    Participant

    Is there a way to make my page display this?:

    – 12:00 AM – 12:00 PM > (Good Morning)

    – 12:00 PM – 06:00PM > (Good Afternoon)

    – 06:00 PM – 12:00 AM > (Good Evening)

    #77553
    eXo
    Member

    This works for me:

    Code:

    <?php
        $cD 
    date(“G”);
        if(
    $cD <= ’12’){
            echo 
    ‘Good Morning’;
        }else if(
    $cD <= ’18’){
            echo 
    ‘Good Afternoon’;
        }else{
            echo 
    ‘Good Evening’;
        }
    ?>

    But like this it will get the current server time. so if the visiter is from another GMT area then it doesn’t work correctly for that visiter.

    #78081
    Capt Otis
    Member

    If you use php, you will get the server time not the person’s local time (as eXo above me said). You can use javascript to get the person’s local time (or atleast the time they have on their computer) and render the page from there. A quick google search can give you the function for that.

    -T

    #78211
    Pete Oxenham
    Member

    I agree with the two above posts, it should be generated with Javascript

    Javascript:

    Code:
    window.onload = function () {
    timegreeting();
    }

    function timegreeting() {
    var now = new Date();
    var greet;
    /* If before 11:00 */
    if (now.getHours() < 11) { greet = "

    Good morning!

    “;
    }
    /* If between 11:00 and 17:00 (5:00, all times are expressed in 24 hr time) */
    else if (now.getHours() < 17) { greet = "

    Whatever

    “;
    }
    /* If after 17:00 */
    else {
    greet = “

    Good evening!

    “;
    }
    document.getElementById(“greeting”).innerHTML = greet;
    }

    HTML:

    Code:

    I used that script a long time ago, but it seems to work well

Viewing 6 posts - 1 through 6 (of 6 total)
  • The forum ‘Back End’ is closed to new topics and replies.