Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>this can be a bit overwhelming, but in the link @Amine Matmati provided you have all the tools you need. With it you could easily walk through each day from the starting timestamp up to the present, and skip weekends and off hours. </p> <p>It's a bit clunky, but it would work. </p> <p><code>strtotime(str, timestamp)</code> takes a string that is a command in almost plain English, and if you want, a reference timestamp. This is what you would use to run from your current timestamp all the way to the end timestamp.</p> <p>ie. <code>strtotime('end of the working day', timestamp of when the job started);</code> </p> <p><em>[NB: 'end of the day' is not an acceptable string, check the link to the PHP manual at the bottom for that, I just wanted you to see how it would be useful to you]</em></p> <p>So if you built a loop that walked from the original timestamp to the present, you could count the number of working hours as you went.</p> <p>I'll show you the logic in pseudo code: </p> <pre><code>$Present is present timestamp; $Start is the starting timestamp; $Hours will be the accumulated working hours between starting timestamp and present timestamp; loop while present timestamp not reached { if $Start does not occur on the same day as $Present{ if $Start occurs inside of working hours { find the time to the end of the working day; add that time to $Hours; } find next day; if the next day is Saturday{ update $Start to the working start of next Monday; } else{ update $Start to the working start of the next day; } } else{ find the time between $Start and $Present; add that time to $Hours; update $Start to $Present or Break; } } </code></pre> <p><strong>It does assume</strong> that the starting time does not occur on weekends, and does not occur outside (ie. before) working hours on the same day as the present timestamp, but controlling for those is very easy. </p> <p>Things that will be your friend in this are: </p> <p>@Amine Matmati's link: <a href="https://stackoverflow.com/questions/2091838/time-difference-between-2-dates-ignoring-weekend-time">Time difference between 2 dates ignoring weekend time</a></p> <p>PHP date(): <a href="http://php.net/manual/en/function.date.php" rel="nofollow noreferrer">http://php.net/manual/en/function.date.php</a> <br>PHP strtotime(): <a href="http://www.php.net/manual/en/function.strtotime.php" rel="nofollow noreferrer">http://www.php.net/manual/en/function.strtotime.php</a></p> <p><strong>Happy coding!</strong></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload