radiations3 Posted August 5, 2011 Share Posted August 5, 2011 PHPSENSIE helped me in creating a timer which calculates the difference between the dates and echo the remaining remaining days. Now i want to know how to create such a timer in which the days left and time also displays in hour:minutes and seconds Kindly help if you have any piece of code. Quote Link to comment https://forums.phpfreaks.com/topic/243985-creating-count-down-timer-javascript-passing-values-through-database/ Share on other sites More sharing options...
phpSensei Posted August 5, 2011 Share Posted August 5, 2011 I can help you again with PHP, however this is a javascript question.... Wrong section. http://stuntsnippets.com/javascript-countdown/ Quote Link to comment https://forums.phpfreaks.com/topic/243985-creating-count-down-timer-javascript-passing-values-through-database/#findComment-1252891 Share on other sites More sharing options...
radiations3 Posted August 5, 2011 Author Share Posted August 5, 2011 I can help you again with PHP, however this is a javascript question.... Wrong section. http://stuntsnippets.com/javascript-countdown/ The link you've shared kindly tell me how can i pass values through database like last time you told me to... thanks! else kindly help me even in php how to create such a timer which enables the countdown in days:hours:minutes . I just want such timer that's all... Although the day calculating timer you gave i am using that at the moment. Quote Link to comment https://forums.phpfreaks.com/topic/243985-creating-count-down-timer-javascript-passing-values-through-database/#findComment-1252895 Share on other sites More sharing options...
phpSensei Posted August 5, 2011 Share Posted August 5, 2011 I don't have your code on my computer, can you post it again so I can make the modifications? Quote Link to comment https://forums.phpfreaks.com/topic/243985-creating-count-down-timer-javascript-passing-values-through-database/#findComment-1252896 Share on other sites More sharing options...
radiations3 Posted August 5, 2011 Author Share Posted August 5, 2011 <?php $check = '10/09/11'; // Set it to the recordset or a variable from where the date is comming from the specific field from database $date = strtotime($check); // Just put in between these two parenthesis the date, wherever it may come from. $event_year = date('Y',$date); $event_month = date('n',$date); $event_day = date('j',$date); $difference = ((mktime (0,0,0,$event_month,$event_day,$event_year) - time()) / 3600); $days_left = (int) ($difference/24); print $days_left . ' days left until ' . $event_day . '-' . $event_month.'-'.$event_year; ?> Quote Link to comment https://forums.phpfreaks.com/topic/243985-creating-count-down-timer-javascript-passing-values-through-database/#findComment-1252900 Share on other sites More sharing options...
phpSensei Posted August 6, 2011 Share Posted August 6, 2011 I keep forgetting about you <?php $check = '08/07/11 19:50:00'; // Set it to the recordset or a variable from where the date is comming from the specific field from database $date = strtotime($check); // Just put in between these two parenthesis the date, wherever it may come from. $countdown = date('Y-m-d h:i:s',$date); $event_year = date('Y',$date); $event_month = date('n',$date); $event_day = date('j',$date); $event_hour = date('G',$date); $event_mins = date('i',$date); $event_sec = date('s',$date); $difference = mktime ($event_hour,$event_mins,$event_sec,$event_month,$event_day,$event_year) - time(); $days_left = floor($difference/60/60/24); $hours_left = floor(($difference - $days_left*60*60*24)/60/60); $minutes_left = floor(($difference - $days_left*60*60*24 - $hours_left*60*60)/60); print "Today's Date is. ".date('Y-m-d h:i:s',time()) . '<br />'; print "Countdown Date is. ".$countdown . '<br />'; print $days_left . ' days<br />'; print $hours_left . ' Hours <br />'; print $minutes_left . ' Minutes'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/243985-creating-count-down-timer-javascript-passing-values-through-database/#findComment-1252939 Share on other sites More sharing options...
radiations3 Posted August 6, 2011 Author Share Posted August 6, 2011 The code you gave is really very much helpful one last question currently static time is getting displayed can we do it dynamically with any function or what (if you can provide me that that'll be so nice of you) like 1 days 2 hours 14 mins after one minute the time get diplayed as automatically 1 days 2 hours 13 mins THANKS!!! Quote Link to comment https://forums.phpfreaks.com/topic/243985-creating-count-down-timer-javascript-passing-values-through-database/#findComment-1252979 Share on other sites More sharing options...
phpSensei Posted August 6, 2011 Share Posted August 6, 2011 you want to make the code a function with given arguments? Or what do you mean dynamically. Quote Link to comment https://forums.phpfreaks.com/topic/243985-creating-count-down-timer-javascript-passing-values-through-database/#findComment-1252985 Share on other sites More sharing options...
radiations3 Posted August 6, 2011 Author Share Posted August 6, 2011 i meant such a code in which the values of the timer gets minus itself automatically it doesn't require the page reload as in groupin.pk The code you gave is perfect but the page needed to be reload to see the accurate time left after some interval of time.. Quote Link to comment https://forums.phpfreaks.com/topic/243985-creating-count-down-timer-javascript-passing-values-through-database/#findComment-1253002 Share on other sites More sharing options...
phpSensei Posted August 6, 2011 Share Posted August 6, 2011 This would be very much Javascript appropriate.. However if you want to go down that road, you can set a redirect timer, which I strongly not recommend. Otherwise the user should just refresh the page <meta http-equiv="refresh" content="600"> Content is how many seconds need to pass before refreshing. Mark Topic As Solved. Quote Link to comment https://forums.phpfreaks.com/topic/243985-creating-count-down-timer-javascript-passing-values-through-database/#findComment-1253008 Share on other sites More sharing options...
radiations3 Posted August 6, 2011 Author Share Posted August 6, 2011 hmmmm if you have any code then kindly do provide which helps me passing the variables comming from your give code to that javascript code in order to get dynamic count down i know php is not good approach for it till then i am stick with the code you gave me first of days only... Thanx alot for help Quote Link to comment https://forums.phpfreaks.com/topic/243985-creating-count-down-timer-javascript-passing-values-through-database/#findComment-1253012 Share on other sites More sharing options...
phpSensei Posted August 6, 2011 Share Posted August 6, 2011 I'll leave this to you http://www.google.ca/webhp?hl=en#hl=en&sa=X&ei=Z6I8Tte5HubksQK28dQT&ved=0CBYQvwUoAQ&q=Javascript+countdown&spell=1&bav=on.2,or.r_gc.r_pw.&fp=e0300863683066b3&biw=1912&bih=933 If you want to pass your variable to Javascript from PHP then you can simply do <script> <?php echo "var a = 08/07/11 19:50:00"; ?> </script> Quote Link to comment https://forums.phpfreaks.com/topic/243985-creating-count-down-timer-javascript-passing-values-through-database/#findComment-1253014 Share on other sites More sharing options...
AyKay47 Posted August 6, 2011 Share Posted August 6, 2011 I'll leave this to you http://www.google.ca/webhp?hl=en#hl=en&sa=X&ei=Z6I8Tte5HubksQK28dQT&ved=0CBYQvwUoAQ&q=Javascript+countdown&spell=1&bav=on.2,or.r_gc.r_pw.&fp=e0300863683066b3&biw=1912&bih=933 If you want to pass your variable to Javascript from PHP then you can simply do <script> <?php echo "var a = 08/07/11 19:50:00"; ?> </script> this suggestion makes me queasy Quote Link to comment https://forums.phpfreaks.com/topic/243985-creating-count-down-timer-javascript-passing-values-through-database/#findComment-1253030 Share on other sites More sharing options...
phpSensei Posted August 6, 2011 Share Posted August 6, 2011 AyKay, he is pulling the date from Mysql, he can either do that or Ajax... I wouldn't bother with Ajax for a simple integration task. Since PHP is a server side language, vice versa of this method won't be possible, some languages like ASP.NET can... but not PHP Correction in that example <script> <?php echo "var a = '08/07/11 19:50:00'"; ?> </script> Quote Link to comment https://forums.phpfreaks.com/topic/243985-creating-count-down-timer-javascript-passing-values-through-database/#findComment-1253034 Share on other sites More sharing options...
radiations3 Posted August 6, 2011 Author Share Posted August 6, 2011 Got !!Finally!! the final working code Thanx to phpSensei for helping me out <form name="count"> <input type="text" size="75" name="count2"> </form> <script> document.count.count2.disabled=false; /* Count down until any date script- By JavaScript Kit (www.javascriptkit.com) Over 200+ free scripts here! */ //change the text below to reflect your own, var before="Availing this deal!" var current="Deal Over!" var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec") function countdown(yr,m,d){ theyear=yr;themonth=m;theday=d var today=new Date() var todayy=today.getYear() if (todayy < 1000) todayy+=1900 var todaym=today.getMonth() var todayd=today.getDate() var todayh=today.getHours() var todaymin=today.getMinutes() var todaysec=today.getSeconds() var todaystring=montharray[todaym]+" "+todayd+", "+todayy+" "+todayh+":"+todaymin+":"+todaysec futurestring=montharray[m-1]+" "+d+", "+yr dd=Date.parse(futurestring)-Date.parse(todaystring) dday=Math.floor(dd/(60*60*1000*24)*1) dhour=Math.floor((dd%(60*60*1000*24))/(60*60*1000)*1) dmin=Math.floor(((dd%(60*60*1000*24))%(60*60*1000))/(60*1000)*1) dsec=Math.floor((((dd%(60*60*1000*24))%(60*60*1000))%(60*1000))/1000*1) if(dday==0&&dhour==0&&dmin==0&&dsec==1){ document.forms.count.count2.value=current return } else document.forms.count.count2.value="Only "+dday+ " days, "+dhour+" hours, "+dmin+" minutes, and "+dsec+" seconds left until "+before setTimeout("countdown(theyear,themonth,theday)",1000) } //enter the count down date using the format year/month/day <?php $check = '10/09/11'; // Set it to the recordset or a variable from where the date is comming from the specific field from database $date = strtotime($check); // Just put in between these two parenthesis the date, wherever it may come from. $x = date('Y',$date); // year $y = date('n',$date); // month $z = date('j',$date); // date ?> var x = <?php echo $x;?> var y = <?php echo $y;?> var z = <?php echo $z;?> countdown(x,y,z) </script> <p align="center"><font face="arial" size="-2">This free script provided by</font><br> <font face="arial, helvetica" size="-2"><a href="http://radiations3.com">JavaScript Kit & modified by Raidations3</a></font></p> Quote Link to comment https://forums.phpfreaks.com/topic/243985-creating-count-down-timer-javascript-passing-values-through-database/#findComment-1253048 Share on other sites More sharing options...
phpSensei Posted August 6, 2011 Share Posted August 6, 2011 Np, glad you got it. Quote Link to comment https://forums.phpfreaks.com/topic/243985-creating-count-down-timer-javascript-passing-values-through-database/#findComment-1253056 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.