Jump to content

Count down???


astralaaron

Recommended Posts

Is this a countdown of minutes or seconds? or is it a countdown to a certain date? Javascript could do either of them, but if you want something like "There are 3 days left until the event" PHP would probably be better.

Link to comment
Share on other sites

Is this a countdown of minutes or seconds? or is it a countdown to a certain date? Javascript could do either of them, but if you want something like "There are 3 days left until the event" PHP would probably be better.
I am much more formilliar with PHP than javascript -this would be a countdown to a certain date - 6 weeks atleastthis would put food on my table if i can get it working!edit:: how would this work in PHP ??
Link to comment
Share on other sites

1. Store the finish date in a file that php can access. It needs to be in a format that php can understand. You might just build a little script to return the date to yourself and write it manually to a file. I suggest gmdate(U) and then just keep working with GMT seconds.2. Everytime you need to generate countdown info, open the date file, grab the date, and close the file. Now you can compare that date with the finish date. Do some math and make a string based on how much time is left. You decide if you want to leave it at days, days + hours + minutes, whatever.3. If you want one of those clickers that updates by the 1/10 or 1/100 second, you'll have to send the date to javascript and let the client do the small counting. Ajax is not dependably fast enough for that kind of accuracy.If you really had to, you could store the date as a variable in an external javascript. Then link to that script and javascript can do all the math.Whatever works best.

Link to comment
Share on other sites

1. Store the finish date in a file that php can access. It needs to be in a format that php can understand. You might just build a little script to return the date to yourself and write it manually to a file. I suggest gmdate(U) and then just keep working with GMT seconds.2. Everytime you need to generate countdown info, open the date file, grab the date, and close the file. Now you can compare that date with the finish date. Do some math and make a string based on how much time is left. You decide if you want to leave it at days, days + hours + minutes, whatever.3. If you want one of those clickers that updates by the 1/10 or 1/100 second, you'll have to send the date to javascript and let the client do the small counting. Ajax is not dependably fast enough for that kind of accuracy.If you really had to, you could store the date as a variable in an external javascript. Then link to that script and javascript can do all the math.Whatever works best.
thanks, this is starting to make more sense to me now.how would you calculate the time between the 2 dates ?also, gmdate(u)can you explain how to use that?i usually get a date like this:$date=date('m/d/y ');$h=date('h');if (date("A")=="PM") {$h+=12;}$date.=$h.date(':i:s'); also: if using php to make this countdown... how is it possible to count the seconds / minutes while the page is open?
Link to comment
Share on other sites

date() gets the local time where the server is.gmDate() gets absolute Greenwich Mean Time. Otherwise it's exactly the same. I recommended it so you'd have a fixed standard to go on. But that's up to you.gmDate/date(U) gets the absolute number of seconds elapsed since the Unix Epoch (January 1 1970 00:00:00 GMT). I personally store dates in this way because it's a short string with no spaces and no ambiguity. That makes the data easy to retrieve. It's all for convenience.It would be stupid to reference everything off January 1, 1970. No one uses it that way. It's useful for comparing a start date to a finish date. Since seconds are easily calculated with reference to 60 and 24 and 365 if you need it, your math is not difficult.All that REALLY matters for your function, I think, is storing a date in a file in some format and then comparing it to today's date. Store it in any format you like.

Link to comment
Share on other sites

date() gets the local time where the server is.gmDate() gets absolute Greenwich Mean Time. Otherwise it's exactly the same. I recommended it so you'd have a fixed standard to go on. But that's up to you.gmDate/date(U) gets the absolute number of seconds elapsed since the Unix Epoch (January 1 1970 00:00:00 GMT). I personally store dates in this way because it's a short string with no spaces and no ambiguity. That makes the data easy to retrieve. It's all for convenience.It would be stupid to reference everything off January 1, 1970. No one uses it that way. It's useful for comparing a start date to a finish date. Since seconds are easily calculated with reference to 60 and 24 and 365 if you need it, your math is not difficult.All that REALLY matters for your function, I think, is storing a date in a file in some format and then comparing it to today's date. Store it in any format you like.
ok, but with a PHP / mysql countdown.. it will just change each time the page is loaded? because i need the minutes and seconds to be counting down in real time when they are on the page.
Link to comment
Share on other sites

If you want to have it PHP but with real-time changes you will need to pass the PHP variable to JavaScript, then use JavaScript to do the changing. Something like

var date = <?php echo $date; ?>;

Link to comment
Share on other sites

If you want to have it PHP but with real-time changes you will need to pass the PHP variable to JavaScript, then use JavaScript to do the changing. Something like
var date = <?php echo $date; ?>;

cool i thought it would be something like that.I am not going to be able to do this unless i learn some javascript :)
Link to comment
Share on other sites

When passing dates between PHP and Javascript you need to worry about time zone differences. A single timestamp means different things in different time zones. So instead of passing a single timestamp from PHP to Javascript you will want to pass the parts individually, the month, date, year, hour, etc. Then Javascript can initialize itself with the right time in the user's time zone.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...