SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Member
    Join Date
    Mar 2005
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Php Date Countdown - Need help writing if statement

    as the title suggests, i have incorportated a date countdown on my site. Im new to php so im learning it as i go sort of thing. I was wondering if someone could give me some help on how to write a if statement for when the days of my countdown equals zero, that it would display a different message.
    heres the code
    Code:
    <?PHP 
    $day = 19;     // Enter the day of the date to countdown to
    $month = 02;   // Enter the month of the date to countdown to
    $year = 2006;   // Enter the year of the date to countdown to
    print ("Message1");
    ?>
    So what im asking is whenever the days is greater then 0 it will display the first message, otherwise it will display another message...

    Note: I did take some code out of the message to display it here.

  2. #2
    SitePoint Member
    Join Date
    Mar 2005
    Location
    Hampshire, UK
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Ryan,

    I'm not brilliant at php, but wouldn't it be something like:

    PHP Code:
    <?PHP 
    $day 
    19;     // Enter the day of the date to countdown to
    $month 02;   // Enter the month of the date to countdown to
    $year 2006;   // Enter the year of the date to countdown to

    if ($day 0) {

    print (
    "Message1");

    } else {

    print (
    "Message2");

    }
    ?>
    hth

  3. #3
    SitePoint Zealot
    Join Date
    May 2004
    Location
    Oxford, UK
    Posts
    138
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $countdown mktime(0002192006);
    if (
    time() < $countdown) {
        
    // Display before countdown date message
    } else {
        
    // Diplay after countdown date message

    I think that should do what you're looking for.

  4. #4
    SitePoint Member
    Join Date
    Mar 2005
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by lokksta
    Hi Ryan,

    I'm not brilliant at php, but wouldn't it be something like:

    PHP Code:
    <?PHP 
    $day 
    19;     // Enter the day of the date to countdown to
    $month 02;   // Enter the month of the date to countdown to
    $year 2006;   // Enter the year of the date to countdown to

    if ($day 0) {

    print (
    "Message1");

    } else {

    print (
    "Message2");

    }
    ?>
    hth

    This is what i tried earlier, but i kept getting 0 days left....the second message doesn't appear

  5. #5
    SitePoint Member
    Join Date
    Mar 2005
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help Please!!

    bump

  6. #6
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Did you try TomH's suggestion:
    PHP Code:
    <?php
    $day 
    19;
    $month 2;
    $year 2006;
     
    $countdown mktime(000$month$day$year);
     
    $today mktime(000date('n'), date('j'), date('Y'));
    if (
    $today $countdown) {
        echo 
    'before the date message';
    } else {
        echo 
    'on or after the date message';
    }
    ?>

  7. #7
    SitePoint Member
    Join Date
    Mar 2005
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How would i display # of days left until whatever

    would it be $today-time(void)/86400?? thats code i have from another source.

  8. #8
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Might as well use:
    $daysleft = round(($countdown - $today)/86400);
    E.g:
    PHP Code:
    <?php
    $day 
    19;
    $month 2;
    $year 2006;
     
    $countdown mktime(000$month$day$year);
     
    $today mktime(000date('n'), date('j'), date('Y'));
     
    $daysleft round(($countdown $today)/86400);
    if (
    $today $countdown) {
        echo 
    'before the date message. Days left = '.$daysleft;
    } else {
        echo 
    'on or after the date message';
    }
    ?>

  9. #9
    SitePoint Member
    Join Date
    Mar 2005
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    is there a way to have the .$daysleft first and then a message??
    such as $daysleft til message

  10. #10
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just change:
    echo 'before the date message. Days left = '.$daysleft;
    to whatever you like, e.g:
    echo $daysleft.' days before the message.';

  11. #11
    SitePoint Member
    Join Date
    Mar 2005
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks man, greatly appreciate your help


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
  •