...

View Full Version : Looking for a Countdown Timer to reset itself daily at midnight



just cool
03-29-2010, 11:25 PM
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

Fou-Lu
03-30-2010, 12:20 AM
Hmm, lets see if this works:


$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.

Len Whistler
03-30-2010, 12:46 AM
And here is a code snippet for EST, just put it in your header.php file and all PHP dates will be in EST.


date_default_timezone_set('America/New_York');


----------------

just cool
03-30-2010, 05:43 AM
Hmm, lets see if this works:


$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.

kbluhm
03-30-2010, 05:50 AM
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.

Len Whistler
03-30-2010, 06:16 AM
I would go with an all Javascript solution.


http://articles.techrepublic.com.com/5100-10878_11-6016329.html





--------

just cool
03-30-2010, 01:27 PM
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.

Fou-Lu
03-30-2010, 04:57 PM
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:



$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.

DJCMBear
03-30-2010, 05:22 PM
To get your current time to set right use this:


<?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.

sitNsmile
03-30-2010, 06:11 PM
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.

just cool
03-31-2010, 01:21 AM
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.

dados
03-03-2011, 02:31 PM
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?

dniwebdesign
03-04-2011, 01:47 AM
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?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum