SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Wizard
    Join Date
    Dec 2005
    Posts
    1,718
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help with mktime () basic countdown script?

    Hi all just spent an hour or 2 setting up a basic countdown for a no. of events in javascript then realized if the users clock is wrong all your events dates are wrong...

    So I'm using mktime to get the server time, the below works great but I need to add a few more event dates... nye is just an example, how can I add more events?

    So I can:
    print "New Years Eve $days days";
    print "Some event $days days";
    print "Some other event $days days";

    PHP Code:
    <?php
    $target 
    mktime(00012312008) ;
    $today time () ;
    $difference =($target-$today) ;
    $days =(int) ($difference/86400) ;
    print 
    "New Years Eve $days days";
    ?>

    Thanks CB

  2. #2
    SitePoint Wizard
    Join Date
    Dec 2005
    Posts
    1,718
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi

    I've managed to put something together which works, but is this the best way?

    PHP Code:
    <?php

    $e1 
    mktime(0006152008) ;
    $e2 mktime(0008232008) ;
    $e3 mktime(0008242008) ;
    $nye mktime(00012252008) ;
    $today time () ;
    $difference =($e1-$today) ;
    $difference2 =($e2-$today) ;
    $difference3 =($e3-$today) ;
    $difference4 =($nye-$today) ;
    $days =(int) ($difference/86400) ;
    $days2 =(int) ($difference2/86400) ;
    $days3 =(int) ($difference3/86400) ;
    $days4 =(int) ($difference4/86400) ;
    print 
    "e1 $days days";
    print 
    "e2 $days2 days";
    print 
    "e3 $days3 days";
    print 
    "NYE $days4 days";
    ?>
    Thanks

  3. #3
    SitePoint Wizard stereofrog's Avatar
    Join Date
    Apr 2004
    Location
    germany
    Posts
    4,324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try GregorianToJD

    PHP Code:
    list($d$m$y) = explode(' 'date('d m Y'));
    $days GregorianToJD(1231$y) - GregorianToJD($m$d$y);
    print 
    "New Years Eve $days days"

  4. #4
    SitePoint Wizard
    Join Date
    Dec 2005
    Posts
    1,718
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks frog, so your saying this is better than mktime and I'm still left with the problem of adding extra event dates?

    Are you suggesting:

    PHP Code:
    list($d$m$y) = explode(' 'date('d m Y'));
    $days GregorianToJD(1231$y) - GregorianToJD($m$d$y);
    $days2 GregorianToJD(823$y) - GregorianToJD($m$d$y);
    $days3 GregorianToJD(824$y) - GregorianToJD($m$d$y);
    print 
    "New Years Eve $days days";
    print 
    "Event 2 $days2 days";
    print 
    "Event 3 $days3 days"
    ??

    Cheers Cb


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
  •