+ Reply to Thread
Results 1 to 6 of 6

Calculate hours worked within a time range

  1. #1
    Registered User
    Join Date
    11-19-2017
    Location
    Oslo, Norway
    MS-Off Ver
    15.3
    Posts
    19

    Calculate hours worked within a time range

    I feel that I have searched the entire internet without much luck, so I sincerely hope that some of you are able to solve this.

    I need a formula that returns hours worked if they occur within the range of 00:00 and 06:00 (midnight to 6AM). If they do not occur within the range, it should return 0.

    An issue is that starting time is before midnight and ending time exceeds midnight.

    In the picture below, the formula should return "6" in cell C5 and "0" in cell C6.


    Screen Shot 2017-11-19 at 12.45.24.png

    Any advice or guidance will be greatly appreciated.
    Last edited by ilohyou; 11-22-2017 at 04:04 PM.

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

    Re: Calculate hours worked within a time range

    Try this formula in C5 copied down

    =(B5-A5)*24+(B5<A5)*6-MEDIAN(B5*24,6,24)+MEDIAN(A5*24,6,24)

    format cells as general or number
    Audere est facere

  3. #3
    Registered User
    Join Date
    11-19-2017
    Location
    Oslo, Norway
    MS-Off Ver
    15.3
    Posts
    19

    Re: Calculate hours worked within a time range

    Quote Originally Posted by daddylonglegs View Post
    Try this formula in C5 copied down

    =(B5-A5)*24+(B5<A5)*6-MEDIAN(B5*24,6,24)+MEDIAN(A5*24,6,24)

    format cells as general or number
    It worked perfectly. Thank you!

  4. #4
    Registered User
    Join Date
    11-19-2017
    Location
    Oslo, Norway
    MS-Off Ver
    15.3
    Posts
    19

    Re: Calculate hours worked within a time range

    I also need formula that returns "2" in Cell C2 and C3. Is there an easy way to do this?


    Screen Shot 2017-11-22 at 17.58.43.png

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

    Re: Calculate hours worked within a time range

    The previous formula was the generic format for time periods that cross midnight (I know it didn't quite cross it, but touched it). For daytime time periods the formula is a little simpler

    =(B2<A2)*2+MEDIAN(B2*24,6,8)-MEDIAN(A2*24,6,8)

    If you want to revise the formula for other daytime periods then the *2 represents the hours in the period and 6 and 8 in the MEDIAN functions obviously the start and end times

  6. #6
    Registered User
    Join Date
    11-19-2017
    Location
    Oslo, Norway
    MS-Off Ver
    15.3
    Posts
    19

    Re: Calculate hours worked within a time range

    Perfect! Thank you for the explanation.
    Last edited by AliGW; 11-22-2017 at 04:07 PM. Reason: Unnecessary quotation removed.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Using IF function to calculate hours worked - non military time
    By Kanne26 in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 10-07-2015, 11:11 AM
  2. [SOLVED] [SOLVED] Calculate time worked inside Regular Hours and Over Time
    By myxamhatosis in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 04-07-2015, 09:16 PM
  3. Replies: 7
    Last Post: 01-02-2015, 04:06 PM
  4. Replies: 4
    Last Post: 02-12-2013, 07:01 AM
  5. Replies: 2
    Last Post: 02-11-2013, 02:26 PM
  6. Calculating basic hours worked, between a time range and premium hours worked
    By RoyLittle0 in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 01-07-2012, 06:59 AM
  7. Replies: 0
    Last Post: 01-05-2012, 06:23 AM

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