Results 1 to 2 of 2

 

Thread: PHP Code: Morning, Afternoon & Evening

  1. #1
    Frostie's Avatar
    Moderator

    Status
    Offline
    Join Date
    Aug 2003
    Location
    Wirral
    Posts
    3,217
    Thanks
    61
    Thanked 60 Times in 27 Posts


    I am trying to get a simple What/If PHP statement working based on the time of my server. If its midnight->11am it should say Good Morning. Between 12noon & 5pm then Good Afternoon, otherwise Good Evening...

    Should this code work?
    Code:
    <?php
    $hour = date("G");
        if ($hour >= 0 || $hour <= 11) {
            echo "Good morning";
    	    } else {
                if ($hour >= 12 || $hour <= 17) {
                    echo "Good afternoon";
            	    } else {
    	        	echo "Good evening";
    	       	}
            }
    ?>

  2. #2
    paulb567's Avatar
    Registered User

    Status
    Offline
    Join Date
    Dec 2006
    Posts
    169
    Thanks
    7
    Thanked 22 Times in 20 Posts
    Nearly. You want to use ANDs not ORs

    Code:
    <?php
    $hour = date("G");
        if ($hour >= 0 && $hour <= 11) {
            echo "Good morning";
    	} else if ($hour >= 12 && $hour <= 17) {
            echo "Good afternoon";
        } else {
    	   	echo "Good evening";
    	}
    ?>
    Nothing to see here

  3. The Following User Says Thank You to paulb567 For This Useful Post:

    Barry (11-05-11)



Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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
  •  
To Top

Content Relevant URLs by vBSEO 3.5.0 RC2