+1 vote
by
There are two unix timestamps:
$start = 123456789; // в прошлом
$finish = time(); // текущее
How to count the number of seconds between them, but only during working hours.
I.e., only consider the seconds between 07:00:00 and 22:45:00 inclusive, and only from Monday to Friday inclusive.
Any ideas?
by
What about the holidays?
by
wataru it is not necessary
by
Sergey Pugovkin Besides, different categories of workers have different working weeks. from 36 to 40 hours. and different countries have different laws.

1 Answer

0 votes
by
 
Best answer
Any ideas?
Very easy - you need to count the number of working days not including the first and the last and multiply by the number of seconds between 07:00:00 and 22:45:00. Then, if the first day is a working day, add the number of seconds between the beginning of that day (or 07:00:00 if the timestamp is earlier) and 22:45:00. Then, if the last day is a working day, add the number of working seconds in it.

Turning a timestamp into a date, checking what day of the week the date falls on and adding a day to the date are all simple tasks.
...