```Srikanth Jeeva <sri.jjhero / gmail.com> writes:

> Brian Candler wrote:
>> Srikanth Jeeva wrote:
>>> but i need the total hours between 9am-5pm, between the given dates..
>>> can any one plz help??
>>
>> Not sure what you mean. Do you mean (date2 - date1 + 1) * 8 ?
>>
>> Use to_i on the answer if you don't want Rational arithmetic.
>
> hi brain,
>
> i mean..
>
> date1="November 5th, 2008, 10:30 am"
> date2="November 7th, 2008, 6:00 pm"
>
> i want only the working hours between 10:30 am to 6.00 pm,in these
> dates...
>
> date can also be,
>
> date1="March 5th, 2005, 5:30 am"
> date2="November 7th, 2006, 9:00 pm"
>
> all i need is working hours between these dates...
>
> first day & last days time makes complications here.

If you have partial days, apply the same principle than in my previous
answer, trim off the partial days, compute the trimmed off hours, and
multiply the days by the working-hours-per-day.

if day(start)=day(end) then
min(5pm,hour(end)) - max(9am,hour(start))
else
(min(5pm,hour(end)) - 9am)
+ (5pm - max(9am,hour(start)))
+ previous algo with (start + 1day) and (end - 1 day)
end

--
__Pascal Bourguignon__

```