The forums have permanently moved to forum.kirupa.com. This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.


Results 1 to 2 of 2

Thread: Count down timer

  1. #1
    brndn's Avatar
    1,096
    posts
    has cme t snuf da rooster

    Count down timer

    Hi all just mashed up this from a few examples I found but is a handy way to count down days, hours, minutes..



    PHP Code:
    <?php
    $DATE 
    datum();

    function 
    datum($datum=true) {
    $sign "+"// Whichever direction from GMT to your timezone. + or -
    $h "0"// offset for time (hours)
    $dst true// true - use dst ; false - don't

    if ($dst==true) {
        
    $daylight_saving date('I');
        if (
    $daylight_saving){
            if (
    $sign == "-"){ $h=$h-1;  }
            else { 
    $h=$h+1; }
        }
    }
    $hm $h 60;
    $ms $hm 60;
    if (
    $sign == "-"){ $timestamp time()-($ms); }
    else { 
    $timestamp time()+($ms); }
    //$gmdate = gmdate("M d Y H:i:s", $timestamp);

    if($datum==true) {
    //return $gmdate;

    return $timestamp;
    }
    else {
    return 
    $timestamp;
    }

    }



    function 
    nicetime($date)
    {
        if(empty(
    $date)) {
            return 
    "No date provided";
        }
       
        
    $periods         = array("second""minute""hour""day");
        
    $lengths         = array("60","60","24","7");
       
        
    $now             strtotime(gmdate("M d Y H:i:s"datum()));
        
        print 
    "<p>NOW:".gmdate("M d Y H:i:s"datum())."</p><p> $now</p>";

        
    $unix_date         strtotime($date);
        
        
           print 
    "<p>THEN:".date("M d Y H:i:s"$unix_date)."</p><p> $unix_date</p>";
           
    // check validity of date
        
    if(empty($unix_date)) {   
            return 
    "Bad date";
        }

        
    // is it future date or past date
        
    if($now $unix_date) {   
            
    $difference     $now $unix_date;
            
    $tense         "ago";
           
        } else {
            
    $difference     $unix_date $now;
            
            echo 
    "<P>DIFFERENCE IS: $difference</P>";
            
            
    $tense         "from now";
        }
       
        for(
    $j 0$difference >= $lengths[$j] && $j count($lengths)-1$j++) {
            
    $difference /= $lengths[$j];
            
                echo 
    "<P>DIFFERENCE: $j $difference</P>";
        }
       
        
    $difference round($difference);
       
        if(
    $difference != 1) {
            
    $periods[$j].= "s";
        }
       
        return 
    "$difference $periods[$j] {$tense}";
    }

    $date "2009-10-19 11:00";
    $result nicetime($date);


    echo 
    $result;
    ?>

  2. #2
    pretty cool ... but
    PHP Code:
    $sign "+"// Whichever direction from GMT to your timezone. + or -
    $h "0"// offset for time (hours)
    $dst true// true - use dst ; false - don't 
    should probably be arguments of the function:

    PHP Code:
    function datum($datum=true,$sign "+",$h "0",$dst true) {

    if (
    $dst==true) {
        
    $daylight_saving date('I');
        if (
    $daylight_saving){
            if (
    $sign == "-"){ $h=$h-1;  }
            else { 
    $h=$h+1; }
        }
    }
    $hm $h 60;
    $ms $hm 60;
    if (
    $sign == "-"){ $timestamp time()-($ms); }
    else { 
    $timestamp time()+($ms); }
    //$gmdate = gmdate("M d Y H:i:s", $timestamp);

    if($datum==true) {
    //return $gmdate;

    return $timestamp;
    }
    else {
    return 
    $timestamp;
    }


    Let us live so that when we come to die even the undertaker will be sorry. - Mark Twain
    Don't PM me your CSS, xHTML, JS or PHP questions. I will not reply to ANY IE6 questions.

Thread Information

Users Browsing this Thread

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012