+ Reply to Thread
Results 1 to 3 of 3

Calc difference bet two times using Networkdays excl. weekends and non-working hours

  1. #1
    Registered User
    Join Date
    05-09-2011
    Location
    princeton, new jersey
    MS-Off Ver
    Excel 2010
    Posts
    3

    Calc difference bet two times using Networkdays excl. weekends and non-working hours

    Using Excel 2007, the following formula works except when the problem reported is outside of business hours:

    IF(NETWORKDAYS($E11,NOW())=1,(MIN($D$8,MOD(NOW(),1))-MAX($B$8,MOD($E11,1))),(NETWORKDAYS($E11,NOW())-2)*(600/1440)+($D$8-MAX(MOD($E11,1),$B$8))+MIN(MOD(NOW(),1),$D$8)-$B$8)

    where
    $E11 = Problem reported timestamp 10/22/2012 3:23:00 PM
    Now() = current date and time

    Business hours : $B$8 = 9:00 AM $D$8 = 5:00 PM

    Need your kind assistance to tweak it where it can work regardless of when the problem is reported.
    thank you

  2. #2
    Registered User
    Join Date
    05-09-2011
    Location
    princeton, new jersey
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Calc difference bet two times using Networkdays excl. weekends and non-working hours

    From a previous Closed thread I used the 2nd formula, as shown below, it worked in almost all cases except for some quirky reason it gave an answer of 0:00 for some items that were opened and closed on the same day, and in one instance on the next day. However in few instances it worked even when on the same day.
    e.g. works in the following instance:
    Start Time End Time
    Sep 28, 2012 9:27:15 AM Sep 28, 2012 3:30:21 PM
    Sep 27, 2012 10:18:58 AM Sep 27, 2012 10:45:32 AM

    [B]does not work in the following instances:
    Start Time End Time
    Sep 4, 2012 5:39:27 AM Sep 4, 2012 8:46:10 AM
    Sep 4, 2012 8:08:04 AM Sep 4, 2012 8:38:46 AM
    Sep 4, 2012 6:09:47 PM Sep 5, 2012 1:30:48 AM



    Assuming the following cell references
    A2 = start date/time
    B2 = end date/time
    D2 = weekday start time (08:00)
    E2 = weekday end time (17:00)
    holidays F2:F28

    In your example it appears that all start/end dates are non-holiday weekdays, although your start and or end times might be outside business hours. If this is always the case try this formula in C2, formatted as [h]:mm and copied down the column

    =(NETWORKDAYS(A2,B2,F$2:F$28)-1)*(E$2-D$2)+MEDIAN(MOD(B2,1),D$2,E$2)-MEDIAN(MOD(A2,1),D$2,E$2)

    If you want a formula which accomodates start or end dates which might be Sats, Suns or holidays, i.e. start and end times can be anything then use

    =(NETWORKDAYS(A2,B2,F$2:F$28)-1)*(E$2-D$2)+IF(NETWORKDAYS(B2,B2,F$2:F$28),MEDIAN(MOD(B2,1),D$2,E$2),E$2)-MEDIAN(NETWORKDAYS(A2,A2,F$2:F$28)*MOD(A2,1),D$2,E$2)

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

    Re: Calc difference bet two times using Networkdays excl. weekends and non-working hours

    Those look like my formulas - you'll need to use the longer (second) version if you have start or end times on weekends or holidays, otherwise the first one should suffice

    What results did you get for these three?

    Quote Originally Posted by jpatel View Post
    [B]does not work in the following instances:
    Start Time End Time
    Sep 4, 2012 5:39:27 AM Sep 4, 2012 8:46:10 AM
    Sep 4, 2012 8:08:04 AM Sep 4, 2012 8:38:46 AM
    Sep 4, 2012 6:09:47 PM Sep 5, 2012 1:30:48 AM
    I get 0:46, 0:30 and 0:00 respectively with D2 as 08:00 - all those results look correct to me (for the last one, if you start at 6 PM and end at 1:30 AM next morning that period doesn't intersect with any work hours).

    If you have D2 as 09:00 then you'll get 0:00 for all three because none of them intersect the working period
    Last edited by daddylonglegs; 10-24-2012 at 02:40 PM.
    Audere est facere

+ 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