Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 13 of 13
  1. #1
    New to the CF scene
    Join Date
    Mar 2010
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Smile Looking for a Countdown Timer to reset itself daily at midnight

    I currently have a timer but its in Javascript so it works only on the clients computer time but i need it to work with the server time so that i can set it to a timezone and make sure that it resets itself at midnight EST time no matter what time zone you are in. I was told its better to use PHP for this countdown to work properly but im a very newbie in PHP.

    Can someone indicate a script that i can use ..... PLEASE

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Hmm, lets see if this works:
    PHP Code:
    $iTimeTo strtotime("00:00 tomorrow");
    $iDiffTime $iTimeTo time();

    printf("Remaining: %s\n"date('H:i:s'$iDiffTime)); 
    That work?
    I'm a little curious if the 00:00 is valid with the tomorrow modifier. I believe it is in the GNU but I could be mistaken. If not, we'll find another mktime based solution.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #3
    Senior Coder Len Whistler's Avatar
    Join Date
    Jul 2002
    Location
    Vancouver, BC Canada
    Posts
    1,323
    Thanks
    26
    Thanked 100 Times in 100 Posts
    And here is a code snippet for EST, just put it in your header.php file and all PHP dates will be in EST.

    PHP Code:
    date_default_timezone_set('America/New_York'); 

    ----------------
    Leonard Whistler

  • #4
    New to the CF scene
    Join Date
    Mar 2010
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fou-Lu View Post
    Hmm, lets see if this works:
    PHP Code:
    $iTimeTo strtotime("00:00 tomorrow");
    $iDiffTime $iTimeTo time();

    printf("Remaining: %s\n"date('H:i:s'$iDiffTime)); 
    That work?
    I'm a little curious if the 00:00 is valid with the tomorrow modifier. I believe it is in the GNU but I could be mistaken. If not, we'll find another mktime based solution.
    Fou-Lu i did try what you give me but it did not work. Actually i tried it at 10:42 pm EST and when i load a demo page to see the script in action the time was 19:24:54 which is the wrong time and its not counting down as well. It just stays there until i refresh the page. What i want is for the time to keep counting down by the second and it refresh itself at midnight to 23:59:59 and counts down again each day and it must be seen counting down on the webpage.

  • #5
    Senior Coder kbluhm's Avatar
    Join Date
    Apr 2007
    Location
    Philadelphia, PA, USA
    Posts
    1,509
    Thanks
    3
    Thanked 258 Times in 254 Posts
    What exactly is the timer doing? Counting up? Down? What determines the count? Does it start at zero and increment by the second? Does it start at 100 and decrement every so many seconds, minutes, hours, etc? How exactly is it supposed to behave? The more we know the better we'll be able to help.
    Last edited by kbluhm; 03-30-2010 at 04:53 AM.

  • #6
    Senior Coder Len Whistler's Avatar
    Join Date
    Jul 2002
    Location
    Vancouver, BC Canada
    Posts
    1,323
    Thanks
    26
    Thanked 100 Times in 100 Posts
    I would go with an all Javascript solution.


    http://articles.techrepublic.com.com...1-6016329.html





    --------
    Leonard Whistler

  • #7
    New to the CF scene
    Join Date
    Mar 2010
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by kbluhm View Post
    What exactly is the timer doing? Counting up? Down? What determines the count? Does it start at zero and increment by the second? Does it start at 100 and decrement every so many seconds, minutes, hours, etc? How exactly is it supposed to behave? The more we know the better we'll be able to help.
    I will try to make my request as clear as a i can.

    I would like to have a countdown timer on my website that will count down from 12:00:01 am and end at midnight again of the same day (the clock should count down a full 24 hours) then it will automatically reset itself and count down again each and every day. The count down should display hours : minutes : seconds and it should be seen on the webpage counting down as well just like a digital watch but instead of going up its should be counting down to end the day. I would also like to it to go with the server time and not client computer time so it will only count down according to the server time.

    One more thing .... each day a new trivia question will be posted and ppl have 1 day to answer the trivia question for a chance to win something (that is why the script is counting down). Will the script be able to automatically load a new trivia each day at midnight as the timer resets or do i have to load the trivia manually? If im getting way out of my head here then lets forget this last part.

    I was told it can only be done with PHP but i also see that Len Whistler is talking about JavaScript. However it can be done i will certainly appreciate the advice.

  • #8
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    I'm half suprised that that gave you a number in the first place! Wow, learn something new every day!

    Ok, lets take a look. At this point, we have no idea if the code I provided for you is actually flawed or not. That is based on Server time and offset, not client time. So, use what Len Whistler provided to change you're offset to a valid EST timezone. Next, modify the code I provided to this:

    PHP Code:
    $iTimeTo strtotime("00:00 tomorrow"); 
    $iDiffTime $iTimeTo time(); 

    printf("Current Time: %s\n"date('H:i:s'));
    printf("Remaining: %s\n"date('H:i:s'$iDiffTime)); 
    That will also show you what the current time is. Compare the Remaining to the Current to see if its actually functional or not.

    As for the questions, yes that can only really be controlled with PHP; Javascript can display these and whatnots, but there is no guarentee that the user cannot go back. That can be done easily as well, but you'll need a datasource of some sorts to store this in. As for an actual 'count down', PHP is not capable of performing this. Being a server side language, all you can ask for is data, not dynamic updates. What you can do is pass data to Javascript and let it count.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #9
    Senior Coder DJCMBear's Avatar
    Join Date
    Mar 2010
    Location
    United Kindom
    Posts
    1,173
    Thanks
    14
    Thanked 136 Times in 136 Posts
    To get your current time to set right use this:
    PHP Code:
    <?php 
    date_default_timezone_set
    ("EST");
    ?>
    And to see the countdown working on the page without refreshing you will need to use javascript as php isn't client-side and javascript is.

    You can use your php codes to generate the times for the javascript to use and then use javascript to count the time down.
    Official BinPress hand picked coder.
    For anyone worried about SQL injection go have a look at my small yet powerful script here.
    Go Pledge for Light Table, if it hit's $300,000 Python and other languages will get added.
    I am 1 of 65,608 people to get a Pebble Watch :P

  • #10
    Regular Coder sitNsmile's Avatar
    Join Date
    Dec 2009
    Location
    Charlotte, NC
    Posts
    358
    Thanks
    19
    Thanked 2 Times in 2 Posts
    You cant make a script to reset anything on its own at the time you wish. You'd need to of course have the script do the reset function which are said in previous replies, but you would need to put this into the "Cronjob" to tell it to run that script at the time you wish (midnight) which automatically tells it to use server time.

  • #11
    New to the CF scene
    Join Date
    Mar 2010
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Well i guess that what i wanted to get done will have to be done in JavaScript so i would post it in the JavaScript section and see if i can get any help there.

    A Special Thank You to ALL who tried to help me and i appreciate it very well.

  • #12
    New to the CF scene
    Join Date
    Mar 2011
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi to everybody I need to all same thing Countdown Timer to reset itself daily at midnight and count time by server.. Can please send me the script if somebody have this?

  • #13
    Regular Coder dniwebdesign's Avatar
    Join Date
    Dec 2003
    Location
    Carrot River, Saskatchewan
    Posts
    846
    Thanks
    15
    Thanked 10 Times in 10 Posts
    You can't reset the timer "automatically" but you can make it so when the user visits the page it resets itself without any action by the user. I don't have the ability for Cronjobs on my host (at this time), so most of my scripts are automatically ran when a user visits my website.

    So in turn, it can be done via PHP. Just a matter of when you want it to reset to countdown?
    Dawson Irvine
    CEO - DNI Web Design
    http://www.dniwebdesign.com


  •  

    Posting Permissions

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