Show 'x' if time is between this and that

Discussion in 'PHP' started by Kremechoco, Dec 11, 2011.

  1. #1
    How would I go about doing this?
    I want it to show one thing under one specified timezone between two times.
    Example:
    Time is between 1:00 AM and 1:00 PM. It will show "X" while if
    Time is between 1:01 PM and 12:59 AM, It will show "y"
     
    Kremechoco, Dec 11, 2011 IP
  2. NIKOLO

    NIKOLO Member

    Messages:
    19
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    46
    #2
    Use 24-hour format and PHP date funtion.

    Example:

    <?php
    
    $x = "Bla Bla Bla X!";
    
    $y = "Bla Bla Bla Y!";
    
    if(date("G")>0 & date("G")<13){
         // Time between 01:00AM & 1:00PM or between 01:00 & 13:00 hour with 24 hour format.
         echo $x;
    } else {
         // Time between 01:00PM & 01:00AM or between 13:00 & 01:00 hour with 24 hour format.
         echo $y;
    }
    
    ?>
    Code (markup):
    http://php.net/manual/en/function.date.php
     
    NIKOLO, Dec 11, 2011 IP