+ Reply to Thread
Results 1 to 22 of 22

hours worked after certain time

  1. #1
    Registered User
    Join Date
    04-24-2012
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    13

    hours worked after certain time

    Hello,

    This is my first post here. I have actually posted this thread in another forum :-

    http://www.mrexcel.com/forum/showthread.php?t=630842

    but have yet to get a reply.

    In cells A1 and B2 I have the start and end times of a shift. These are specified in the format dd:mm:yy hh:mm e.g 23/04/2012 16:00 and 24/04/2012 03:00. I need the number of hours worked after 20:00 hours. In this case the answer is 7 hours.

    Note as this is for a hospital, there is not a fixed "ground zero" i.e a fixed point in time where rollover occurs - as there are always staff working.

    Thanks

    Kaps

  2. #2
    Forum Expert icestationzbra's Avatar
    Join Date
    01-07-2004
    MS-Off Ver
    2007, 2010
    Posts
    1,421

    Re: hours worked after certain time

    2mr_kaps, could you upload a sample file that closely resembles your real-life data?

  3. #3
    Forum Expert ben_hensel's Avatar
    Join Date
    01-26-2012
    Location
    Northeast USA
    MS-Off Ver
    Office 365
    Posts
    2,043

    Re: hours worked after certain time

    So, what you need is
    Please Login or Register  to view this content.
    right??

    Unfortunately it's not that simple because of the format... do you have a sample file for us to play with?

  4. #4
    Forum Contributor
    Join Date
    01-24-2011
    Location
    Sheppey
    MS-Off Ver
    Excel 2010
    Posts
    239

    Re: hours worked after certain time

    See attached sheet, example may help with what you need.
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    04-24-2012
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: hours worked after certain time

    As requested. Thanks

    Kaps
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    04-24-2012
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: hours worked after certain time

    And I think my opening post is confusing. When I meant after 20:00 hours I meant the hours worked after 8.00 p.m - not elapsed time in erxcess of 20 hours worked. Sorry for any confusion.

  7. #7
    Forum Expert icestationzbra's Avatar
    Join Date
    01-07-2004
    MS-Off Ver
    2007, 2010
    Posts
    1,421

    Re: hours worked after certain time

    see if this works for your needs...

    you will need to put it through some rigorous testing.

    EDIT: updated formula yet again...
    Attached Files Attached Files
    Last edited by icestationzbra; 04-30-2012 at 12:05 PM. Reason: earlier file had incorrect formula

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

    Re: hours worked after certain time

    Try this formula

    =MAX(0,B3-MAX(A3,INT(A3)+"20:00"))
    Audere est facere

  9. #9
    Forum Expert icestationzbra's Avatar
    Join Date
    01-07-2004
    MS-Off Ver
    2007, 2010
    Posts
    1,421

    Re: hours worked after certain time

    @kaps,

    i was testing with some "made up" data and found that my formula is not bringing correct results for the following:

    Start Time
    23-04-12 04:00

    End Time
    25-04-12 03:00

    i do not know if you will ever have such a case. but since this is a hospital, you never know! i will try to see if i can fix my formula, or may be some expert will help you...

  10. #10
    Registered User
    Join Date
    04-24-2012
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: hours worked after certain time

    Thank you for your contributions. It is much appreciated. The case of working through two days is not relevant - so if they start on the 23rd then they will stop on the 24th.

  11. #11
    Registered User
    Join Date
    04-24-2012
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: hours worked after certain time

    I have been testing icestationzebra's formulae- and although it generally works, I have found an example where it gives an unexpected result. See the last example in the attachment where the shift starts at 01:00 and finishes at 09:00 a.m. I would expect an answer of 8 hours. However I am getting 13 hours. thanks

    Kaps
    Attached Files Attached Files

  12. #12
    Forum Expert icestationzbra's Avatar
    Join Date
    01-07-2004
    MS-Off Ver
    2007, 2010
    Posts
    1,421

    Re: hours worked after certain time

    hi kaps,

    a few things:

    1. my formula was not correct - i have fixed the error.
    2. daddylonglegs is an expert - i would defer to his solution and would recommend that you prefer his over mine.
    3. neither dll's nor my formula would give you your expected result in the case of "23-04-12 01:00 to 23-04-12 09:00" because your original condition was that only the hours worked after 8:00 PM should be considered - 1:00 is 1 AM and 9:00 is 9 AM; both are before 8 PM and hence dll's and my (updated) formula would spit out 0:00 hours. has that changed?
    Last edited by icestationzbra; 04-30-2012 at 12:26 PM.
    - i.s.z -
    CSE, aka Array aka { }, formulae are confirmed with CONTROL+SHIFT+ENTER.
    Replace commas ( , ) with semicolons ( ; ) in formulae, if your locale setting demands.
    All good ideas are courtesy resources from this forum as well as others around the web.
    - e.o.m -

  13. #13
    Registered User
    Join Date
    04-24-2012
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: hours worked after certain time

    thanks - I see what you mean about both being before 8 p.m. However I do need it to give a result of 8 hours in this scenario. Your formulae was better than Daddy Long Legs - (don't put yourself down - I know these formulae are extremely complicated). Can you suggest an amendment ? Thanks

    Kaps

  14. #14
    Forum Expert icestationzbra's Avatar
    Join Date
    01-07-2004
    MS-Off Ver
    2007, 2010
    Posts
    1,421

    Re: hours worked after certain time

    ohhh... you hurt dll's feelings, he is not gonna like it... hell hath no fury like a scorned mosquito with long legs.

    let's see - changing the formula is no big deal. if we change the formula for one data-point, however, your other results will change too. look at your data-set and see if you can give me some bases on which you think all of your other results will be valid, along with achieving the goal with your latest data-point.

  15. #15
    Registered User
    Join Date
    04-24-2012
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: hours worked after certain time

    Ok - lets say that the existing results are valid as they are - apart from the new case.

    Note that I am thinking out aloud here - as there seems to be no easy answer.

    In the new case, lets look at the proportion of the shift that is before 6.00 a.m in the morning. If this is greater than 50% then you consider it as part of the previous day. If it is more than 50% then you consider it as a new day.

    so 01:00 to 09:00 a.m is 8 hours, 01:00 to 06:00 is 5 hours. 5/8 is 62.5% - which is greater than 50% - so there are 8 hours worked after 8 p.m.

    If however somebody worked from 04:00 to 10:00 a.m - which is 6 hours - with 2 hours before 6.00 a.m - this is 33.33% - less than 50% - so it counts as 0 hours.

    Sorry if this sounds terribly convoluted but I have struggled with this problem for weeks !!! Any help greatly appreciated. Thanks

    Kaps

    P.S Sorry Daddy Long Legs if I caused any offence.

  16. #16
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: hours worked after certain time

    I'm confused-daddylonglegs' formula produces exactly the right results based on your initial requirement so why are you ignoring it?
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  17. #17
    Registered User
    Join Date
    04-24-2012
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: hours worked after certain time

    Sorry - think I know what I need now (once and for all). I need the hours worked between 8 p.m and 6 a.m. Ignore ALL previous posts. thanks

    regards

    Kaps
    Last edited by kaps_mr2; 05-01-2012 at 04:53 AM.

  18. #18
    Registered User
    Join Date
    04-24-2012
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: hours worked after certain time

    And you are right Daddy Long Legs formulae does work - I think I mistyped it - and got confused.

    If somebody could suggest a variation for my new scenario of the hours worked between 8:00p.m and 6.00 a.m it would be appreciated.

    And severe apologies for annoying Daddy Long Legs - just been struggling with this for too long.
    Last edited by kaps_mr2; 05-01-2012 at 06:24 AM.

  19. #19
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: hours worked after certain time

    maybe a variation on daddylonglegs' formula
    =MAX(0,B3-MAX(A3,INT(A3)+"20:00"))+MAX(0,MIN(B3,INT(B3)+"6:00")-A3)*(HOUR(A3)<6)

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

    Re: hours worked after certain time

    no problem here.....

    For all hours between 20:00 and 06:00 try this formula

    =B3-A3-(INT(B3)-INT(A3))*"14:00"-MEDIAN(MOD(B3,1),"6:00","20:00")+MEDIAN(MOD(A3,1),"6:00","20:00")

  21. #21
    Registered User
    Join Date
    04-24-2012
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: hours worked after certain time

    thanks everybody for your help !!!

  22. #22
    Forum Expert icestationzbra's Avatar
    Join Date
    01-07-2004
    MS-Off Ver
    2007, 2010
    Posts
    1,421

    Re: hours worked after certain time

    a very rudimentary approach...
    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