+ Reply to Thread
Results 1 to 5 of 5

Formula Calculation That Excludes Specific Hours of the Day

  1. #1
    Registered User
    Join Date
    02-04-2013
    Location
    Kansas City
    MS-Off Ver
    Excel 2010
    Posts
    3

    Formula Calculation That Excludes Specific Hours of the Day

    ere's what I am trying to accomplish.

    Cell 1 contains a date and time in it.

    Cell 2 contains a date and time in it

    Cell 3 needs to contain the difference between Cell 2 and Cell 1, excluding any weekends and any time that occurs before 0800hrs and after 1700hrs.

    For example

    if Cell 1 read 1/23/2013 0800

    and Cell 2 read 1/24/2013 1400

    assuming 1/23 and 1/24 were weekdays, Cell 3 should read 15 hrs.

    So a more complex calculation might be:

    Cell 1 reads 2/1/2013 (which is a Friday) 1300

    Cell 2 reads 2/4/2013 (which is a Monday) 0900

    Cell 3 should read 5 hrs.

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

    Re: Formula Calculation That Excludes Specific Hours of the Day

    If your start and end date/times are always within the working hours you can use this formula

    =(NETWORKDAYS(A2,B2)-1)*("17:00"-"8:00")+MOD(B2,1)-MOD(A2,1)

    or if you want to allow any start/end times/dates try

    =(NETWORKDAYS(A2,B2)-1)*("17:00"-"8:00")+IF(NETWORKDAYS(B2,B2),MEDIAN(MOD(B2,1),"8:00","17:00"),"17:00")-MEDIAN(NETWORKDAYS(A2,A2)*MOD(A2,1),"8:00","17:00")

    Assumes start date/time in A2 and end date/time in B2 - custom format result cell as [h]:mm

    The above gives you results in time format like 28:15 - if you want decimal format like 28.25 then multiply the whole formula by 24 and format result cell as number
    Last edited by daddylonglegs; 02-04-2013 at 04:32 PM. Reason: corrected typos
    Audere est facere

  3. #3
    Registered User
    Join Date
    02-04-2013
    Location
    Kansas City
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Formula Calculation That Excludes Specific Hours of the Day

    Quote Originally Posted by daddylonglegs View Post
    If your start and end date/times are always within the working hours you can use this formula

    =(NETWORKDAYS(A2,B2)-1)*("17:00"-"8:00")+MOD(B2,1)-MOD(A1,1)

    or if you want to allow any start/end times/dates try

    =(NETWORKDAYS(A2,B2)-1)*("17:00"-"8:00")+IF(NETWORKDAYS(B2,B2),MEDIAN(MOD(B2,1),"8:00","17:00"),"17:00")-MEDIAN(NETWORKDAYS(A2,A2)*MOD(A1,1),"8:00","17:00")

    Assumes start date/time in A2 and end date/time in B2 - custom format result cell as [h]:mm

    The above gives you results in time format like 28:15 - if you want decimal format like 28.25 then multiply the whole formula by 24 and format result cell as number
    Start and end times are not always within the reporting threshold I defined.

    Also, what format do the date/times need to be in, in their respectice Cells (Cell 1 & Cell 2 in my example)?

    Also I notice an A1 in the last line of the formula. What does that represent?

    Thanks!
    Last edited by BuddL33; 02-04-2013 at 04:27 PM.

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

    Re: Formula Calculation That Excludes Specific Hours of the Day

    Sorry, that was a typo, all references should be to A2 or B2, i.e.

    =(NETWORKDAYS(A2,B2)-1)*("17:00"-"8:00")+IF(NETWORKDAYS(B2,B2),MEDIAN(MOD(B2,1),"8:00","17:00"),"17:00")-MEDIAN(NETWORKDAYS(A2,A2)*MOD(A2,1),"8:00","17:00")

    A2 and B2 should be valid date/time values in excel (e.g. if you re-format as general the values change to numbers) - other than that the exact date/time format doesn't matter

  5. #5
    Registered User
    Join Date
    02-04-2013
    Location
    Kansas City
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Formula Calculation That Excludes Specific Hours of the Day

    Quote Originally Posted by daddylonglegs View Post
    Sorry, that was a typo, all references should be to A2 or B2, i.e.

    =(NETWORKDAYS(A2,B2)-1)*("17:00"-"8:00")+IF(NETWORKDAYS(B2,B2),MEDIAN(MOD(B2,1),"8:00","17:00"),"17:00")-MEDIAN(NETWORKDAYS(A2,A2)*MOD(A2,1),"8:00","17:00")

    A2 and B2 should be valid date/time values in excel (e.g. if you re-format as general the values change to numbers) - other than that the exact date/time format doesn't matter
    Ok I figured as much with the A1 issue. Thanks. This is the closest I've been to fixing this sheet and I am terrible with Excel.

    So the author inserted that dates using MM/DD/YYYY format followed by a time stamp.

    For example.

    The start date cell (cell 1) reads 1/23/2013 10:00

    The end date cell (cell 2) reads 1/24/3013 8:16

    The result cell I asked you to calculate reads 1/0/1900 7:16.

    what I am reading that as is that the "1/0/1900" represents months days and years, so if the result time is less than 24 hours it will always read 1/0/1900. However if it's say 26 hours then it would read 1/1/1900 2:00. Is that correct?

    I'm looking to clean that up so that it's more easily interpreted by the reader.

    The format I am trying to achieve is in hours and minutes as a cumulative total. If I format the result to be hh:mm, once it crosses 24 it wants dd in the formating, when I would prefer it keep counting on past 24. Is that possible?
    Last edited by BuddL33; 02-04-2013 at 05:00 PM.

+ 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