Fog Juice Posted August 14, 2010 Share Posted August 14, 2010 Hello, what I'm trying to do is figure out a formula or equation that will help me to activate a script X amount of times a day where X is set by the user. My problem is discovering how many times left to activate the script it on the day they set X. For example, the user sets the script to activate 5 times day, or in other words, every 17280 seconds (since there are 86400 seconds in a day). Now, when activating it each day it is easy to keep track of because you can just calculate each block by 17280 seconds. My problem is how do I figure out how many times are left on the day the user sets the script. For example, if the user sets the script to activate 5 times a day and there is only half a day left, the script should only activate a few more times that day. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/210743-activating-script-five-times-a-day-time-math-help-request/ Share on other sites More sharing options...
Daniel0 Posted August 14, 2010 Share Posted August 14, 2010 Let [imath]x[/imath] be the number of times it should be executed per day. Then the script will run every [imath]S=\frac{x}{86400}[/imath] seconds. Now let [imath]s[/imath] be the number of seconds that have passed that day. Then there will be [imath]\lceil \frac{86400 - s}{S} \rceil[/imath] times left that day. Quote Link to comment https://forums.phpfreaks.com/topic/210743-activating-script-five-times-a-day-time-math-help-request/#findComment-1099366 Share on other sites More sharing options...
Fog Juice Posted August 15, 2010 Author Share Posted August 15, 2010 Thank you, and I apologize for not being more clear in my question. I've attached an image to make it easier to understand what I'm trying to do. It is easier to show you a diagram rather than give you a word problem. In the image you will see sets of blocks. So for example, there is 86400 seconds in a day and 5 blocks per day. That means each block is 17280 seconds. How can I determine how many seconds are left in each block before the next one is reached? 5 is just an arbitrary number, it could be 10, 50, 1023, or any number the user sets. There could be 1440 blocks a day (each block is 60 seconds), there could be 2000 (each block is 43.2 seconds). [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/210743-activating-script-five-times-a-day-time-math-help-request/#findComment-1099396 Share on other sites More sharing options...
sasa Posted August 15, 2010 Share Posted August 15, 2010 try <?php $time = 200; $each_block = 60; $total_time = 86400; $no_blocks = $total_time / $each_block; $curr_bl = ceil($time / $each_block); $to_end_of_block = $curr_bl * $each_block - $time; $left = $no_blocks - $curr_bl; echo "You are on block num $curr_bl, to the end of this block left $to_end_of_block sec and to the end of the day left $left blocks." ?> Quote Link to comment https://forums.phpfreaks.com/topic/210743-activating-script-five-times-a-day-time-math-help-request/#findComment-1099450 Share on other sites More sharing options...
Fog Juice Posted August 15, 2010 Author Share Posted August 15, 2010 Perfect, thank you! I'm horrible at time math. Quote Link to comment https://forums.phpfreaks.com/topic/210743-activating-script-five-times-a-day-time-math-help-request/#findComment-1099452 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.