Re: Calculate # of minutes during working hours between two dates
| From: | Hugh Bothwell | Date: | Thu, 21 Jun 2001 21:02:10 +0000 |
| Subject: | Re: Calculate # of minutes during working hours between two dates | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-54805@lists.php.net to get a copy of this message | ||
Yick! Three-quarters of the replies to this are not what he asked for, and
the others are really scarily inefficient.
Total work time = (start time to end of first week) + (end of first week to
end of last week) - (end time to end of last week).
This is a non-obvious way to phrase it, but it eliminates the special case
where the start and end dates are in the same week, and it ensures that the
first and last clauses are formed in the same way, ie can be implemented as
calls to the same function.
So it becomes
$worktime =
to_end_of_week($start)
+ per_week*(week($end) - week($start))
- to_end_of_week($end);
I wrote up a demo; you can visit it at
http://www.bothwellmedia.com/worktime.php
"Wim Koorenneef" <wim.koorenneef@home.nl> wrote in message
news:3B30C073.8020609@home.nl...
> Hi all,
>
> I want to calculate the number of minutes between two dates, but only
> those minutes on monday through friday between 08.00 and 17.30.
>
> I could evaluate every minute in the interval against all known minutes
> during working hours, but that's a bit much :-) Any suggestions for a
> better, more efficient algorithm? Tia.