PHP - Daily Countdown
Im looking for some example code for countdowns.
I need to be able to count down to the same time each day for example 9PM each day. and be displayed as 5hr 8m 15s. When the timer runs out, then run some code then start again for the next day. what would be the best route to take for this? Thanks in advance Similar TutorialsHi, This is my first post so dont kill me if i did somthing wrong. Im trying to make a simple php/javascript page that will display the time remaining in each period every day (we have 4 periods per day). I found a nice javascript library from www.hashemian.com and am using the example that he linked to to do multiple countdown timers on one page. The problem i am having is that the only way i can think of to make it so that it counts down to a dynamic date is to specify that date as a variable and then combine it with the string that specifys the rest of the date/time combo for the target date/time. The current live version is at smd75jr.com/test/index2.php The first timer is just a test that im using to make sure i havent completely broken it. THe second timer is the one im trying to troubleshoot, it is currently set for 11:59 PM EST "today". (see code below) Any help would be greatly appreciated!! This is my code: Code: [Select] <html> <head> <title>Multiple Countdown Clocks</title> </head> <body> <div id="clock1">[clock1]</div> <div id="clock2">[clock2]</div> </body> <script language="JavaScript"> StartCountDown("clock1","06/27/2012 9:33 PM -0400") StartCountDown("clock2","periodTest") TodaysDate() //var today = new Date() //var todayMonth = today.getMonth() + 1 //var todayDay = today.getDate() //var todayYear = today.getFullYear() //var todayDate = (todayMonth + "/" + todayDay + "/" + todayYear) var periodTest = (todayDate + " 11:59 PM -0400") var periodA1 = (todayDate + " 8:53 AM -0400") var periodA2 = (todayDate + " 10:26 AM -0400") var periodA31 = (todayDate + " 12:32 PM -0400") var periodLunch1 = (todayDate + " 11:00 AM -0400") var periodLunch2 = (todayDate + " 12:32 PM -0400") var periodA32 = (todayDate + " 11:59 AM -0400") var periodA4 = (todayDate + " 2:05 PM -0400") //function Periods(todayDate, periodA1, periodA2, periodA31, periodA32, periodA4, periodB1, periodB2, periodB31, periodB32, periodB4, periodLunch1, periodLunch2, periodSchoolStart, periodSchoolEnd) // { // var today = new Date() // var todayMonth = today.getMonth() + 1 // var todayDay = today.getDate() // var todayYear = today.getFullYear() // var todayDate = (todayMonth + "/" + todayDay + "/" + todayYear) // // var periodA1 = (todayDate + " 21:25 PM -0400") // } function TodaysDate(todayDate) { var today = new Date() var todayMonth = today.getMonth() + 1 var todayDay = today.getDate() var todayYear = today.getFullYear() var todayDate = (todayMonth + "/" + todayDay + "/" + todayYear) } /* Author: Robert Hashemian (http://www.hashemian.com/) Modified by: Munsifali Rashid (http://www.munit.co.uk/) Modified by: Tilesh Khatri */ function StartCountDown(myDiv,myTargetDate) { var dthen = new Date(myTargetDate); var dnow = new Date(); ddiff = new Date(dthen-dnow); gsecs = Math.floor(ddiff.valueOf()/1000); CountBack(myDiv,gsecs); } function Calcage(secs, num1, num2) { s = ((Math.floor(secs/num1))%num2).toString(); if (s.length < 2) { s = "0" + s; } return (s); } function CountBack(myDiv, secs) { var DisplayStr; var DisplayFormat = "%%D%% Days %%H%%:%%M%%:%%S%%"; DisplayStr = DisplayFormat.replace(/%%D%%/g, Calcage(secs,86400,100000)); DisplayStr = DisplayStr.replace(/%%H%%/g, Calcage(secs,3600,24)); DisplayStr = DisplayStr.replace(/%%M%%/g, Calcage(secs,60,60)); DisplayStr = DisplayStr.replace(/%%S%%/g, Calcage(secs,1,60)); if(secs > 0) { document.getElementById(myDiv).innerHTML = DisplayStr; setTimeout("CountBack('" + myDiv + "'," + (secs-1) + ");", 990); } else { document.getElementById(myDiv).innerHTML = "Period Over"; } } </script> </html> Hi, I can't think how to make a counter which goes up during the day, and when a new day starts it gets reset to 0. How can I do this without relying on visitors to the site to run the script? Cheers, Tom. I have a weird issue. I'm working on something where people will submit hours for a business. Originally it was free form text, but then I figured it may get messy with people doing M-F 9-5 then Monday through Friday, 9AM to 5PM, Mon-Fri, etc. So I switched to a bunch of inputs. It has each day then a select for from and one for to. Data is passed to the script as a form submission. Vars are named HF# and HT# (hours from, hours to and a 0-6 digit for Mon-Sun). I want to take the input and output a string as such:
Mon-Tue, 8:00 AM to 5:00 PM
Thu-Fri, 8:00 AM to 5:00 PM
Sat, 9:00 AM to 1:00 PM
Sun, 12:00 PM to 3:00 PM
I did this:
$formdata = array(); $formdata["hf0"] = "8:00 AM"; $formdata["ht0"] = "4:30 PM"; $formdata["hf1"] = "8:00 AM"; $formdata["ht1"] = "4:30 PM"; $formdata["hf2"] = ""; $formdata["ht2"] = ""; $formdata["hf3"] = "8:00 AM"; $formdata["ht3"] = "4:30 PM"; $formdata["hf4"] = "8:00 AM"; $formdata["ht4"] = "4:30 PM"; $formdata["hf5"] = "9:00 AM"; $formdata["ht5"] = "1:00 PM"; $formdata["hf6"] = "12:00 PM"; $formdata["ht6"] = "3:00 PM"; $WeekDays = array("Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"); $hours = ""; $sd = "Mon"; $ld = ""; $fr = $formdata["hf0"]; $to = $formdata["ht0"]; for ($x=0; $x<=6; $x++) { if (empty($sd) && !empty($formdata["hf$x"])) { $sd = $WeekDays[$x]; $fr = $formdata["hf$x"]; $to = $formdata["ht$x"]; } if ($fr != $formdata["hf$x"] || $to != $formdata["ht$x"]) { $hours .= "$sd" . (($sd==$ld)?", ":" - $ld, ") . " $fr to $to<br/>"; if (!empty($formdata["hf$x"])) { $sd = $WeekDays[$x]; $fr = $formdata["hf$x"]; $to = $formdata["ht$x"]; } else { $sd = ""; } } $ld = $WeekDays[$x]; }($formdata was because I was tired of hitting back, changing the data then resubmitting) This kinda works, but it skips Sunday. There has got to be a better way to do this.. any ideas? Hi... I planned to create db table daily. When day begin button clicked (text box has date Value) master dB can be copied,with the name of text box value ($date). If already day begin then it show day begin done. How can I do that. Please guide me
hi i have daily data table it's contain ID, Date, and Rain i need to make a new table but tendays period ,,, any clues ,,, will be very greatfull thanks a lot ,,, Hey everyone. Currently I have a site set up where I manually edit the txt file and the site pulls it from the text file and displays via php. I wanted to automate it by creating one file which contains the sunset times for the whole year, and have php determine todays date and then display the corresponding sunset time. Can someone please point me in the right direction? maybe it can be set up in a way where each line in the txt file represents the day of the year. ex: Jan 1 would be line 0, Feb 1's sunset time would be on line 31 etc. Thanks Hey all, Im currently working on a site which I save a cookie on users computer for 1 month as well a row in a table with the 1 month expiring date plus cookie id. What I would like to know is if theres a way to make the server check the table every day at say 12pm to see if any corresponding user cookies in each row have expired on that day as to remove them from the table to match the expiring cookie on the users computer? I would like not to have to rely on a user/admin accessing in to make a script run instead have something thats timed to go off automatically instead? Is there anyway of doing this? Thanks! <?php for($test=100; $test!=0; $test--){ echo $test."\n"; sleep(1);} ?> Instead of counting down like 100 99 98 etc how can I make it replace the previous number? So it would just be like 100 then 100 would go away and 99 would replace it and so on Any help is appreciated Here's the code for the countdown timer. It works. At the end of the countdown, it's suppose to show the message "EXPIRED". But that message only shows once I reload the page. The countdown itself stops at 00:00:01. Is there a way to automatically show the message after that, instead of reloading the page to show it? <style> div#counter{ margin: 100px auto; width: 305px; padding:20px; border:1px solid #000000; } div#counter span{ background-color: #00CAF6; padding:5px; margin:1px; font-size:30px; } </style> <?php $target_date = '2019-01-12 05:40:00'; $timeLeft = (strtotime($target_date) - time()) * 1000; ?> <script src="javascripts/timer.js"></script> <script> $(document).ready(function(){ var timeLeft = <?php echo $timeLeft ; ?>; var timer = new Timer($('#counter'), timeLeft); if (timeLeft <= 0) { $('#counter').text('EXPIRED'); } }); </script> <div id="counter"> <span class="hour">00</span> <span class="min">00</span> <span class="sec">00</span> </div> Edited January 11, 2019 by imgrooot Well I usually run my scripts in CLI.. I have it do something then sleep for x amounr of settings, is there anyway to make it show me the seconds counting down instead of just a blinkin cursor? Hi, how would I go about making a countdown to midnight that will auto reset each time it hits midnight. I would like it to use server time and it doesn't have to be live, can just change when the user refreshes. i am using countdown timer,it gets remaining time in seconds and displays cont down.but when i changed the remaining time for the countdown it displays the same old timer and did not update its countdown time. i need a deperate help for it , can some help me. I would like to have this done in php but am about to lose my mind. Just need a script to countdown to midnight, server time. Doesn't have to be live, just something to see when the page is reloaded. Any help would be much aprreciated Hi all, I would like to create a timer showing a countdown from 0% to 100% (representing "power") ending at noon GMT on Sunday 4th September. The countdown started a few weeks ago, hence as of 1pm GMT on Tuesday 1st March, the countdown should be at 15% The "power" increases by 5% every 11 days so by my calculations, the percentage in our countdown should increase by 0.01% every 1900.8 seconds. So, with this theory, how would I go about coding it? I guess since I use GMT, I need to take a timestamp in GMT first, then calculate the difference between this and Sunday 4th September at 12.00pm. I am not sure though which format of time/date is best to do the calculation. Would it be better to use Unix time? Any help, suggestions and/or code is greatly appreciated. Skulty hi all, im looking at a countdown timer and when a user places a bid it resets the timer, exactly like the one used at madbid.com, is this a mixture of javascript and php or just php? if you could point me in the right direction of what to look into that would be very helpful Lee Can anyone help me to make a countdown timer in php? so basically i've made a quiz.. but i want it to have a time of 1 hour 30 mins.. but i dont have any idea of how to make a timer Hey guys and gals!
I am currently working on implementing the following functionality in one of my pages:
Whenever a person with a specific IP address visits the page, an internal countdown timer of 2 hours should be started. Until that timer is active, the only response from the page ANYONE can get would be a predefined echo value. Once the timer has run out, the normal script execution of the rest of the page should be restored.
Any pointers and tips on how to approach that would be greatly appreciated.
Hi Guys! Hoping someone can help me with this. I need to produce a timer which I can embed on a website. It needs to count down the remaining hours until 7pm during the weekdays, then at the weekends count down until 7pm on Monday. Any ideas or points in the right direction would be greatly appreciated! I'm a bit of a newbie! Hi there i was wondering if its possible to have a count down timer (for say 5 mins) that when it reaches 0 a form is updated.. Code: [Select] <?php // set countdown timer for 5 mins $countdown = '300' if ($countdown == '0'){ update the form somehow? }?> <form id="form1" name="form1" method="POST" action="<?php echo $editFormAction; ?>"> <input name="hiddenField" type="hidden" value="<?php echo $row_query['somedata']; ?>" /> <input type="submit" name="Submit" value="Submit" /> </form> I'm a bit of a noob so any help would be ace. Thanks Newbie PHP user here, so go easy on me . I've been trying to make a timer that starts on an arbitrary number of seconds, say 10 for example, then counts down to 0 (and refreshes itself every second for the user to see how much time is remaining), and then some more code is executed when 0 is reached. I attempted to do something like: <?php $goal = time() + 10; while($goal - time() >= 0) { echo "$goal - time()"; sleep(1); } ?> This didn't seem to work as my page just took a while to load - I suspect it was going through the entire while loop before displaying anything rather than just dynamically updating the timer every second. Also when I chose 100 instead of 10, the webpage didn't seem to even finish loading. Also it displayed a lot of odd text - not a timer at all! Help would be much appreciated ! |