Jump to content

Recommended Posts

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!

 

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.

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).

 

 

fogjuicequestion.th.jpg

 

 

[attachment deleted by admin]

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."
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.