ILYAS415 Posted August 12, 2007 Share Posted August 12, 2007 Okay ive needed help on this before and now i need help on it again. Apparentley the person who made it b4 made a mistake somewhere. Basically wat this script is meant to do is count down every 4 hours starting from 00:00am in the morning. Okay i havnt had time to evaluate the script properly but these are 2 possible things that i think are wrong: • The script is counting down from 01:00am instead of 12:00am • OR the script is counting down every 5 hours. Heres the script: <?php $hours = intval(gmdate('h')); $minutes = intval(gmdate('i')); $seconds = intval(gmdate('s')); $hours_left = (4 - ($hours % 4)) - (($minutes)?1:0); $minutes_left = ($minutes)?((60 - $minutes)-(($seconds)?1:0)):0; $minutes_left = str_pad ($minutes_left , 2, '0', STR_PAD_LEFT); $seconds_left = ($seconds)?(60 - $seconds):0; $seconds_left = str_pad ($seconds_left , 2, '0', STR_PAD_LEFT); $hours_left= $hours_left; echo 'Next reset in: '.$hours_left.'h '.$minutes_left.'m '.$seconds_left.'s<br><br>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/64521-solved-need-help-with-4hour-countdown-script/ Share on other sites More sharing options...
ILYAS415 Posted August 13, 2007 Author Share Posted August 13, 2007 Anyone? please its kinda urgent. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/64521-solved-need-help-with-4hour-countdown-script/#findComment-322916 Share on other sites More sharing options...
lemmin Posted August 13, 2007 Share Posted August 13, 2007 The script works perfectly. It doesn't start from a certain time, it just checks to see how much time is left before the hour is divisible by 4. The reason it isn't working for you is because it is using Greenwich Mean Time and you aren't. To fix this, change these three lines from: $hours = intval(gmdate('h')); $minutes = intval(gmdate('i')); $seconds = intval(gmdate('s')); to: $hours = intval(date('h')); $minutes = intval(date('i')); $seconds = intval(date('s')); [/code[ Quote Link to comment https://forums.phpfreaks.com/topic/64521-solved-need-help-with-4hour-countdown-script/#findComment-322926 Share on other sites More sharing options...
reages Posted August 13, 2007 Share Posted August 13, 2007 from the first look, i suspect the gmdate(), but it depends on several factors. first, which 00:00 am are you refering to? client-side or server-side? if server-side, what timezone is your server set at? try using date(). regards Quote Link to comment https://forums.phpfreaks.com/topic/64521-solved-need-help-with-4hour-countdown-script/#findComment-322928 Share on other sites More sharing options...
ILYAS415 Posted August 13, 2007 Author Share Posted August 13, 2007 Nope exactly the same. Btw for my current time (shown on the page) i was also using greenwich mean time and it still came up for me as the same thing it does with date(h) and them others. Quote Link to comment https://forums.phpfreaks.com/topic/64521-solved-need-help-with-4hour-countdown-script/#findComment-322934 Share on other sites More sharing options...
lemmin Posted August 13, 2007 Share Posted August 13, 2007 I just copy and pasted the code. Unchanged it is one hour off. Using date() instead of gmdate(), it works perfectly. If it isn't working for you, you could simply change the original code on this line: $hours = intval(gmdate('h')); to: $hours = intval(gmdate('h'))+1; That should countdown to an hour divisible by four. Quote Link to comment https://forums.phpfreaks.com/topic/64521-solved-need-help-with-4hour-countdown-script/#findComment-322936 Share on other sites More sharing options...
ILYAS415 Posted August 14, 2007 Author Share Posted August 14, 2007 Thanks alot! Its working now! Quote Link to comment https://forums.phpfreaks.com/topic/64521-solved-need-help-with-4hour-countdown-script/#findComment-323417 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.