radiations3 Posted August 5, 2011 Share Posted August 5, 2011 I am using the following code for the count down but this code is not helping me to get the values of start date and ending date from my database any idea how to do it or kindly provide me a working code that gets the value from the database and generate count down timer accordingly <?php $target = mktime(0, 0, 0, 2, 10, 2012) ; $today = time () ; $difference =($target-$today) ; $days =(int) ($difference/86400) ; print "Our event will occur in $days days"; ?> Link to comment https://forums.phpfreaks.com/topic/243897-creating-count-down-timer-in-php/ Share on other sites More sharing options...
phpSensei Posted August 5, 2011 Share Posted August 5, 2011 # Event Date $event_day = 10; $event_month = 2; $event_year = 2012; # Today's Date in TIMESTAMP FORMAT $current_date = time(); # Calculate the difference $difference = ((mktime (0,0,0,$event_month,$event_day,$event_year) - $current_date) / 3600); # Format $days_left = (int) ($difference / 24); # Print our results print $days_left . ' days left until ' . $event_day . '-' . $event_month.'-'.$event_year; Link to comment https://forums.phpfreaks.com/topic/243897-creating-count-down-timer-in-php/#findComment-1252370 Share on other sites More sharing options...
radiations3 Posted August 5, 2011 Author Share Posted August 5, 2011 your code is very helpful just let me know but the date is saved into my backend as the following format: 07/28/11 01:07:30 AM how to pass this into your code??? Link to comment https://forums.phpfreaks.com/topic/243897-creating-count-down-timer-in-php/#findComment-1252373 Share on other sites More sharing options...
phpSensei Posted August 5, 2011 Share Posted August 5, 2011 <?php $date = strtotime('02/10/12 01:07:30 AM'); // 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; ?> Link to comment https://forums.phpfreaks.com/topic/243897-creating-count-down-timer-in-php/#findComment-1252378 Share on other sites More sharing options...
radiations3 Posted August 5, 2011 Author Share Posted August 5, 2011 <?php $date = strtotime('02/10/12 01:07:30 AM'); // 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; ?> can i do this with the following: $date = strtotime('02/10/12 01:07:30 AM'); $enddate = echo $row_Recordset2['date']; $date = strtotime($enddate); Link to comment https://forums.phpfreaks.com/topic/243897-creating-count-down-timer-in-php/#findComment-1252382 Share on other sites More sharing options...
phpSensei Posted August 5, 2011 Share Posted August 5, 2011 YEs ofcourse! mark topic as solved, if your good to go. Link to comment https://forums.phpfreaks.com/topic/243897-creating-count-down-timer-in-php/#findComment-1252386 Share on other sites More sharing options...
voip03 Posted August 5, 2011 Share Posted August 5, 2011 change the date to 02/10/11. what is u'r result. Link to comment https://forums.phpfreaks.com/topic/243897-creating-count-down-timer-in-php/#findComment-1252390 Share on other sites More sharing options...
radiations3 Posted August 5, 2011 Author Share Posted August 5, 2011 yes i recently checked and yeah my issue is being solved one last question: How can we create a countdown timer just like in the following url in which the time also gets minus and displayed dynamically? If you have any link or piece of code then kindly share i'll be very thankful to you and thanks alot for the help..... http://www.groupon.com/ Link to comment https://forums.phpfreaks.com/topic/243897-creating-count-down-timer-in-php/#findComment-1252391 Share on other sites More sharing options...
radiations3 Posted August 5, 2011 Author Share Posted August 5, 2011 change the date to 02/10/11. what is u'r result. the result is: -176 Link to comment https://forums.phpfreaks.com/topic/243897-creating-count-down-timer-in-php/#findComment-1252393 Share on other sites More sharing options...
phpSensei Posted August 5, 2011 Share Posted August 5, 2011 Thats because that date is in the past Voip3, its before the current date. Link to comment https://forums.phpfreaks.com/topic/243897-creating-count-down-timer-in-php/#findComment-1252395 Share on other sites More sharing options...
voip03 Posted August 5, 2011 Share Posted August 5, 2011 yes -176 Link to comment https://forums.phpfreaks.com/topic/243897-creating-count-down-timer-in-php/#findComment-1252396 Share on other sites More sharing options...
phpSensei Posted August 5, 2011 Share Posted August 5, 2011 yes -176 O.O Link to comment https://forums.phpfreaks.com/topic/243897-creating-count-down-timer-in-php/#findComment-1252398 Share on other sites More sharing options...
radiations3 Posted August 5, 2011 Author Share Posted August 5, 2011 Final piece of code thanks to phpSensei <?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; ?> Kindly phpSensei answer my one last question i asked... Link to comment https://forums.phpfreaks.com/topic/243897-creating-count-down-timer-in-php/#findComment-1252399 Share on other sites More sharing options...
voip03 Posted August 5, 2011 Share Posted August 5, 2011 phpSensei thank you. I forgot the date format. Link to comment https://forums.phpfreaks.com/topic/243897-creating-count-down-timer-in-php/#findComment-1252401 Share on other sites More sharing options...
phpSensei Posted August 5, 2011 Share Posted August 5, 2011 I don't see a time on http://www.groupon.com/ phpSensei thank you. I forgot the date format. so did i at one point hahahaha. Link to comment https://forums.phpfreaks.com/topic/243897-creating-count-down-timer-in-php/#findComment-1252403 Share on other sites More sharing options...
radiations3 Posted August 5, 2011 Author Share Posted August 5, 2011 okay then kindly open www.groupin.pk on groupon.com you have to give your email to see the main page i usually give [email protected] Link to comment https://forums.phpfreaks.com/topic/243897-creating-count-down-timer-in-php/#findComment-1252405 Share on other sites More sharing options...
harristweed Posted August 5, 2011 Share Posted August 5, 2011 java script is best for count down timers (imho) http://www.littlewebthings.com/2010/02/jquery-countdown-script/ Link to comment https://forums.phpfreaks.com/topic/243897-creating-count-down-timer-in-php/#findComment-1252423 Share on other sites More sharing options...
radiations3 Posted August 5, 2011 Author Share Posted August 5, 2011 java script is best for count down timers (imho) http://www.littlewebthings.com/2010/02/jquery-countdown-script/ AGREED but i need such a code in which i can pass date from my database and the timer applied to it accordingly.... Link to comment https://forums.phpfreaks.com/topic/243897-creating-count-down-timer-in-php/#findComment-1252478 Share on other sites More sharing options...
phpSensei Posted August 5, 2011 Share Posted August 5, 2011 Radiation start a new thread, i'll help you out, this thread is marked solved anyways. Link to comment https://forums.phpfreaks.com/topic/243897-creating-count-down-timer-in-php/#findComment-1252753 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.