Miss-Ruth Posted December 14, 2010 Share Posted December 14, 2010 I'm curious.... This time difference never ends. it doesn't send 0. Is there a more efficient way in doing this or please could someone tell what's wrong here. <?php $timezone = new DateTimeZone('Africa/Gaborone'); $date = new DateTime('now', $timezone); $start_time=strtotime($date->format('Y-m-d H:i:s')); $end_time=strtotime("2010-12-14 17:9:0"); echo round(abs($start_time - $end_time)); ?> Thanks, Ruth. Quote Link to comment https://forums.phpfreaks.com/topic/221597-0-value/ Share on other sites More sharing options...
denno020 Posted December 14, 2010 Share Posted December 14, 2010 $start_time=strtotime($date->format('Y-m-d H:i:s')); Is this just a typo here or is it how you have it in your code? You will need to enter the actual numbers there, like you have for $end_time. Quote Link to comment https://forums.phpfreaks.com/topic/221597-0-value/#findComment-1147059 Share on other sites More sharing options...
denno020 Posted December 14, 2010 Share Posted December 14, 2010 Oh wait, I'm sorry, I can see what's happening there.. Maybe it's not formatting it properly? Try echoing out $start_time, to see what format it's in? Quote Link to comment https://forums.phpfreaks.com/topic/221597-0-value/#findComment-1147060 Share on other sites More sharing options...
Miss-Ruth Posted December 14, 2010 Author Share Posted December 14, 2010 As you see this outputs the time in seconds. I don't think that's the issue here. It' that this difference never ends. When it reach 0 it jumps into another value and start it all over again. Ruth. Quote Link to comment https://forums.phpfreaks.com/topic/221597-0-value/#findComment-1147062 Share on other sites More sharing options...
Miss-Ruth Posted December 14, 2010 Author Share Posted December 14, 2010 Anyone please... Thanks, Ruth. Quote Link to comment https://forums.phpfreaks.com/topic/221597-0-value/#findComment-1147095 Share on other sites More sharing options...
MMDE Posted December 14, 2010 Share Posted December 14, 2010 What makes you think it should output 0? You have one variable that varies, and one constant. Should produce different results every second! =P Just tell me if there's something I'm missing out on here... Quote Link to comment https://forums.phpfreaks.com/topic/221597-0-value/#findComment-1147120 Share on other sites More sharing options...
Miss-Ruth Posted December 14, 2010 Author Share Posted December 14, 2010 Ok. I'm using this to create a countdown timer. Could someone show me how this should be done or how can I get the time difference between $start_time and $end_time stop at 0. <?php $timezone = new DateTimeZone('Africa/Gaborone'); $date = new DateTime('now', $timezone); $start_time=strtotime($date->format('Y-m-d H:i:s')); $end_time=strtotime("2010-12-14 17:9:0"); echo round(abs($start_time - $end_time)); ?> Thanks, Ruth. Quote Link to comment https://forums.phpfreaks.com/topic/221597-0-value/#findComment-1147270 Share on other sites More sharing options...
mikecampbell Posted December 14, 2010 Share Posted December 14, 2010 Maybe this is what you want? <?php $timezone = new DateTimeZone('Africa/Gaborone'); $date = new DateTime('now', $timezone); $start_time=strtotime($date->format('Y-m-d H:i:s')); $end_time=strtotime("2010-12-14 17:9:0"); if ($start_time>$end_time) echo 0; else echo ($end_time - $start_time); ?> Quote Link to comment https://forums.phpfreaks.com/topic/221597-0-value/#findComment-1147278 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.