Results 1 to 8 of 8

Thread: Time dependant greeting

  1. #1
    Join Date
    Aug 2008
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Time dependant greeting

    Hello,

    Is there a simple way of having my site greet people differently in the morning and afternoon?
    For example if the time is before midday it will display one .jpg that says good morning. In the afternoon it will display an alternative.

    Any thoughts?

  2. #2
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    I'd suggest either PHP or javascript.
    What you would to with php to make this work is to have one variable that will have PM || AM depending on the time. If that variable is AM, make another variable have an image location, and if it is PM otherwhise, then put this variable in an image tag in HTML. Below is a PHP example.
    PHP Code:
    <?php
    $timeOfDay 
    date("A");
    if(
    $timeOfDay == "AM"){
    $imageDisplay "http://www.dynamicdrive.com/forums/designfiles/logo.gif"//morning.gif
    } else {
    $imageDisplay "http://www.dynamicdrive.com/ddincludes/logo.gif";//evening.gif
    }
    echo 
    "<img src='$imageDisplay' />";
    ?>
    Last edited by Nile; 08-21-2008 at 04:48 PM.
    Jeremy | jfein.net

  3. #3
    Join Date
    Aug 2008
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default java

    Hi thank for the reply.
    php is a mystery to me. I thought it was used in conjunction with MySQL.
    How would accomplish the same thing with java?
    Or am I wrong about php being complex?

    Thanks a lot

  4. #4
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    java or javascript? they are very very different in terms of programming language.

    PHP is not as complex as some of the other server-side languages, however if you have no experience in programming or website creation, the methodologies can be confusing when you first start.

    If you were talking about javascript, you can use the following code.


    Put this in your <head> tag.

    Code:
    <script type="text/javascript">
    function displayGreeting() {
         var today = new Date();
         var hr = today.getHours();
         if(hr > 12) {
              document.write('Good Morning'); // morning midnight - 12am
         } else if(hr > 18) {
              document.write('Good Afternoon'); // afternoon 12-6pm
         } else {
              document.write('Good Evening'); // evening 6pm - midnight
         }
    }
    </script>
    put the following whereever you wish to have the script display
    Code:
    <script type="text/javascript">displayGreeting()</script>

  5. #5
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    yes, as Boogyman said, PHP is not complex at all, well at least the basics.

    Boogyman, I don't know if he wanted it to be Morning, Afternoon, and Evening.

    Pswindle, if you only wanted afternoon and evening use this:
    Code:
    <script type="text/javascript">
    function displayGreeting() {
         var today = new Date();
         var hr = today.getHours();
         if(hr > 12) {
              document.write('Good Morning'); // morning midnight - 12am
         } else {
              document.write('Good Evening'); // evening 6pm - midnight
         }
    }
    </script>
    Jeremy | jfein.net

  6. #6
    Join Date
    Aug 2008
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks both.

    I'd found out the document.write way of doing it with javascript (not java as you rightly point out.) but was looking for a way to display a different .jpg according to the time of day.

    Thanks again.

  7. #7
    Join Date
    Aug 2008
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Cracked it I think

    Thanks I've got it.
    Here it is.

    <script type="text/javascript">
    function displayGreeting() {
    var today = new Date();
    var hr = today.getHours();
    if(hr > 12) {
    document.writeln("<img src=\"goodafternoon.jpg\" /img /p>");
    } else if(hr > 18) {
    document.writeln("<img src=\"goodevening.jpg\" /img /p>");
    } else {
    document.writeln("<img src=\"goodmorning.jpg\" /img /p>");
    }
    }
    </script>

  8. #8
    Join Date
    Aug 2008
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Sorry that didn't quite work. This does though.
    Thanks again:

    <script type="text/javascript">
    function displayGreeting() {
    var today = new Date();
    var hr = today.getHours();
    if(hr > 12 && hr < 18) {
    document.writeln("<img src=\"goodafternoon.jpg\" /img /p>");
    } else if(hr > 18) {
    document.writeln("<img src=\"goodevening.jpg\" /img /p>");
    } else {
    document.writeln("<img src=\"goodmorning.jpg\" /img /p>");
    }
    }
    </script>

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •