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"; ?> Quote Link to comment 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; Quote Link to comment 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??? Quote Link to comment 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; ?> Quote Link to comment 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); Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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/ Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
voip03 Posted August 5, 2011 Share Posted August 5, 2011 yes -176 Quote Link to comment Share on other sites More sharing options...
phpSensei Posted August 5, 2011 Share Posted August 5, 2011 yes -176 O.O Quote Link to comment 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... Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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 a@b.com Quote Link to comment 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/ Quote Link to comment 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.... Quote Link to comment 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. Quote Link to comment 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.