SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Hybrid View

  1. #1
    SitePoint Zealot
    Join Date
    Dec 1999
    Location
    Highlands Ranch, CO
    Posts
    193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    if Monday then; else ???

    This question is for PHP coding and not using MySQL.

    I am trying to figure out the code to make:

    if monday then
    code

    else
    code

    I would really like to get this based on SERVER time. Ideally I would like a section of code to execute if the day is Monday, and the server time is 4-7pm.

    The reason for this is to have a 'live chat' image to appear, that gives a link to a chat room, but I only want it to appear on Mondays from 4-7.

    Can someone help me with this?

    TIA!

  2. #2
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $time mktime();
    $hour date("g"$time);
      if (
    date("D-a"$time) == "Mon-pm" && $hour >= && $hour <= 6) {
        print 
    "Live Chat!";
      } 
    I think that should do it. I could be wrong, though.
    Last edited by TWTCommish; Sep 24, 2001 at 14:46.

  3. #3
    SitePoint Wizard Defender1's Avatar
    Join Date
    Apr 2001
    Location
    My Computer
    Posts
    2,808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <?php
    $day 
    date("l");
    $current_hour date("g");

    if (
    $day == "Monday" && $current_hour >= 16 && $current_hour <= 19) {
    //do your code here
    } else {
    // do your alternate coding here
    }
    ?>
    The l (lowercase L) will store the current day of the week into $day and the $current_hour will get the hour of the day with a 24 hour clock (example - 4 pm is 16 etc.. just add 12 to your normal time to get the 24 hour clocks time) then with an if statement you check if it's monday, as well as the hours are between 16 and 19 (4 and 7pm) and do the code you want between the { and }.
    If it's not monday, or it's not between 4 and 7 pm do whatever else code you want after the else statemnt, between the { and }
    Last edited by Defender1; Sep 24, 2001 at 14:54.
    Defender's Designs
    I'm Getting Married!

    Not-so-patiently awaiting Harry Potter Book 7 *sigh*

  4. #4
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well to check if monday is today.
    PHP Code:
    $hour date("H"mktime(date("H")));
    $day date("D");
    if(
    $day == 'Mon'  && ($hour >= 16 && $hour 19)) {
    print 
    "Its monday between 4 and 7 pm";
    }
    else {
    print 
    "Its not monday between 4 and 7 pm";

    Now if you need to adjust the server time to account for a different time zone just change the first line. For example if you live in one time zone and the server is 2 hours behind you. Simply make the line
    PHP Code:
    $hour date("H"mktime(date("H") - 2)); 
    Or two hours ahead
    PHP Code:
    $hour date("H"mktime(date("H") + 2)); 
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  5. #5
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    LOL, three slightly different methods...and I'll bet they all work, too.

  6. #6
    SitePoint Wizard Defender1's Avatar
    Join Date
    Apr 2001
    Location
    My Computer
    Posts
    2,808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    and all within 5 mins too!
    Defender's Designs
    I'm Getting Married!

    Not-so-patiently awaiting Harry Potter Book 7 *sigh*


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
  •