Question : Need to calculate net working hours...  networkHOURS?

I need to be able to calculate the amount of time in hours:minutes between one date/time and another.  I can subtract one from the other and format the output but I need to also subtract weekend days and evenings (a 8-5 workday).

I can get the net working days (networkdays) but that's not what I want.  Is there an easier way than writing a custom function?  If not, please provide general pseudocode for the algorithm.  Thank you.

Example:  If the start value is 12/17/2004 16:00 and the end value is 12/21/2004 10:20 the result should be 12:20.

Answer : Need to calculate net working hours...  networkHOURS?

The CPearson method was too much for me, so I had a go at a different solution:

With start date/time in A1,
End date/time in A2,
In a named range enter a series of dates being dates of holidays covering the date range of the problem,
and in A3 enter:

=(NETWORKDAYS(A1,A2,Holidays)-2)*9+(17-(HOUR(A1)+MINUTE(A1)/60))+((HOUR(A2)+MINUTE(A2)/60)-8)

This formula says add up:
The number of whole workdays less 2 (the first and last), times 9 gives the number of hours for the whole days worked, allowing for holidays per the list of holiday dates,
Plus the hours worked on the first day,
Plus the hours worked on the last day.

Should give the correct total, shows as 12.33, which I hope can be converted back to 12:20. (via formatting?)

Networkdays requires the Excel Analysis toolpack to be loaded via Tools AddIns.

Next part is optional, I just wanted to try out a real example!

I set up 'holidays' as a dynamically named range, thanks to an example in another question from OscarC. My holidays are in column H, with a header label in row 1, and the named range is defined as follows:

=OFFSET($H$2,0,0,COUNTA(Sheet1!$H:$H)-1,1)

So if I add extra values to this column, the range extends automatically. Thanks OscarC! Interestingly, this range is not listed when I press F5, but if I type the name in, Excel highlights the relevant cells.

Regards
Mike
Random Solutions  
 
programming4us programming4us