Jump to content

Creating count down timer (javascript) (passing values through database)


radiations3

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

  ?> 

Link to comment
Share on other sites

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';
  ?>  

Link to comment
Share on other sites

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!!!

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

Got !!Finally!! the final working code

Thanx to phpSensei for helping me out  :D

 


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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.