+ Reply to Thread
Results 1 to 7 of 7

Calculating Elapsed Time within Variable Working Hours

  1. #1
    Registered User
    Join Date
    05-08-2012
    Location
    Wales
    MS-Off Ver
    Excel for Office 365
    Posts
    4

    Calculating Elapsed Time within Variable Working Hours

    Hi there,

    I am trying to work out the elapsed time stock stays in my workplace between working hours - this would be simple enough if the working hours were standard every day, but the hours change on weekends.
    The hours are Mon - Friday 08:00 - 17:30, Saturday 09:00 - 15:00, Sunday 09:00 - 12:00

    Calculating the time if it's on the same day is simple. I'd like excel to be able to recognise the time span and subtract the correct ammount of 'closed' time from the total elapsed.

    I have 4 columns - Date in, time in, date out and time out - I would like a fifth column with 'total working hours'.

    Any help would be greatly appreciated!

  2. #2
    Forum Guru benishiryo's Avatar
    Join Date
    03-25-2011
    Location
    Singapore
    MS-Off Ver
    Excel 2013
    Posts
    5,147

    Re: Calculating Elapsed Time within Variable Working Hours

    hi TIAL, it would be great if u can upload an eg. basically, your Date In should be combined with Time In & Date Out should be combined with Time Out. u can do that by summing them up. It makes the calculations easier cos Excel stores Dates as numbers & Time as decimals.

  3. #3
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675

    Re: Calculating Elapsed Time within Variable Working Hours

    If start and end times will always be within the working hours then you can set up a table showing the hours for each day and then use this formula for elapsed work hours

    =SUMPRODUCT(INT((WEEKDAY(A2-I$3:I$9)+C2-A2)/7),L$3:L$9)+D2-B2+LOOKUP(WEEKDAY(A2),I$3:J$9)-LOOKUP(WEEKDAY(C2),I$3:K$9)

    See attached example

    If your start and end times might be outside work hours that can be accommodated too but it requires a slightly more complex version of that formula
    Attached Files Attached Files
    Audere est facere

  4. #4
    Registered User
    Join Date
    08-03-2011
    Location
    oz
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Calculating Elapsed Time within Variable Working Hours

    your calculation is wrong because it doesnt take into account the half hours from the trading day

  5. #5
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675

    Re: Calculating Elapsed Time within Variable Working Hours

    Quote Originally Posted by nimamoradi View Post
    your calculation is wrong because it doesnt take into account the half hours from the trading day
    example, please

  6. #6
    Registered User
    Join Date
    08-03-2011
    Location
    oz
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Calculating Elapsed Time within Variable Working Hours

    sorry my brain is fried because im working with a similar problem, my manual calculation was wrong. i retract my statement

  7. #7
    Registered User
    Join Date
    08-03-2011
    Location
    oz
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Calculating Elapsed Time within Variable Working Hours

    sla ap.xlsx

    hi DLL
    is it possible to adjust your formula to work with different open / close times based on the store id / store type?

    see attachment as modified from your original
    perhaps by using an if statement or something?
    i have over 5000 lines for stores with different open /close times and this is so close to solving my problem

    thanks in advance
    nima

  8. #8
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675

    Re: Calculating Elapsed Time within Variable Working Hours

    Sorry, I haven't had much time to look at this....

    I used named ranges to name the 3 tables Type1, Type2 and Type3 and then I used this formula for the hours

    =SUMPRODUCT(INT((WEEKDAY(C2-INDEX(INDIRECT("Type"&B2),0,2))+E2-C2)/7),INDEX(INDIRECT("Type"&B2),0,5))+F2-D2+LOOKUP(WEEKDAY(C2),INDEX(INDIRECT("Type"&B2),0,2),INDEX(INDIRECT("Type"&B2),0,3))-LOOKUP(WEEKDAY(E2),INDEX(INDIRECT("Type"&B2),0,2),INDEX(INDIRECT("Type"&B2),0,4))

    see attached

    Note that the formula only works when all start/end times/dates are within working hours, so row 14 is incorrect, for example, because the finish time is 09:31 on a Wednesday and the store hours for type3 don't begin until 11:00 on a Wednesday.

    If you want I can adjust the formula so that it works whether the times are inside or outside working hours
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1