Forum

Notifications
Clear all

A formula that will calculate total working hours based off dates and times

5 Posts
3 Users
0 Reactions
72 Views
(@adaniel)
Posts: 3
Active Member
Topic starter
 

Hello,

I am looking for a formula to calculate total working hours based off date and time and excludes the weekends.  I have attached a spreadsheet that I will be applying the formula to.  See below for data information.

 

Start date: 8/3/16 9:00 am

End date: 8/16/16 12:00 pm

Start time: 6:00 am

End time: 6:00 pm

We work Mon-Thur so Fri, Sat, Sun would be our weekend.

I am looking to get total hours scheduled based on the information above.

 
Posted : 11/08/2016 1:04 pm
(@craigmonty)
Posts: 6
Active Member
 

Hi adaniel.

There doesn't seem to be an attachment.

cheers

 
Posted : 12/08/2016 12:27 am
(@adaniel)
Posts: 3
Active Member
Topic starter
 

Here you go.

 
Posted : 16/08/2016 4:32 pm
(@catalinb)
Posts: 1937
Member Admin
 

Hi Daniel,

The problem is a complex one, there is no simple formula.

You can see how complex things can be here: Schedule Calculator

I suggest using a User Defined Function, there are a few versions available on web. I tested one for you:

Public Function EndDayTimeM(StartTime As Double, Minutes As Long)
Dim rangeH, numH, rangeD, numD, startD, durW, durD, durH, durM, startW, endW, remTime As Long
Dim startH, endDate As Double

rangeH = 8 ' Starting hour of working day
numH = 12 ' Length of working day in hours
rangeD = 2 ' Starting day of working week
numD = 4 ' Length of working week in days

' Calculates offset from 00:00 Monday in starting week
startW = Fix(StartTime) - DatePart("w", StartTime)
startD = DatePart("w", StartTime) - rangeD
startH = (StartTime - Fix(StartTime)) * 24

' Calculates end time in working weeks, hours, minutes
remTime = Minutes + (startD * numH * 60) + ((startH - rangeH) * 60)
durW = Fix(remTime / 60 / numH / numD)
remTime = remTime - (durW * numD * numH * 60)
durD = Fix(remTime / 60 / numH)
remTime = remTime - durD * 60 * numH
durH = Fix(remTime / 60)
remTime = remTime - durH * 60
durM = remTime

' Converts working weeks into calendar weeks
endDate = startW + durW * 7 + rangeD + durD + (rangeH + durH) / 24 + durM / 1440
EndDayTimeM = endDate
End Function

Change the parameters in red as desired (it's set to 12 hours per day, starting from Monday, 4 days per week, each day starts at 8 AM)

The solution comes from: calculating-end-times-with-working-hours-and-skipping-weekends

The function expects minutes for duration, this is the reason I divided your estimated hours by 60, in cell G17 (where I tested the function)

If the work schedule is more complex, with different work hours per day, different start hours, these static parameters can be changed to variables, adding them to function arguments.

 
Posted : 19/08/2016 8:32 am
(@adaniel)
Posts: 3
Active Member
Topic starter
 

Thank you!

I am going to work on this and I will let you know how it goes.  I will let people know about your website and look into purchasing.

Thanks again.

 
Posted : 24/08/2016 9:50 am
Share: