+ Reply to Thread
Results 1 to 17 of 17

Calculating days, hours, min, and sec between two dates excluding weekends

  1. #1
    Registered User
    Join Date
    06-18-2020
    Location
    Arizona
    MS-Off Ver
    Office 365
    Posts
    75

    Calculating days, hours, min, and sec between two dates excluding weekends

    Hi there,

    We have a ticketing system that timestamps when a ticket is created and when it is closed, and I am trying to calculate the sum of time in d:hh:mm:ss between the two but excluding weekends (US). I am aware of NETWORKDAYS() but that works with the exception of a few instances. Tickets open on a Wednesday and closed the next Wednesday are throwing me for a loop.

    For example, in the last row of the table in the file we have calculated 6 net working days (wed to wed) but an elapsed time of 7.17 days when looking at the open and closed date. Shouldn't subtracting 2 weekend days (Sat + Sun) make it 5.17 days?
    Attached Files Attached Files
    Last edited by cph020283; 08-11-2021 at 11:35 PM.

  2. #2
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2403
    Posts
    13,406

    Re: Calculating days, hours, min, and sec between two dates excluding weekends

    It can be confusing.

    I find it best to remember that when subtracting dates the result is end date exclusive. With NETWORKDAYS the result is start and end date inclusive. That's why you'll often see +1 following date subtractions in order to include that closing date.

    If my "explanation" doesn't help try subtracting TODAY's date from TODAY's date. The result is of course 0. Then use TODAY's date for both the start and end date in NETWORKDAYS. It returns 1 (assuming not a weekend).

    Did that help?
    Last edited by FlameRetired; 08-09-2021 at 02:37 PM.
    Dave

  3. #3
    Registered User
    Join Date
    10-07-2011
    Location
    Pompano Beach, FL
    MS-Off Ver
    Excel 365
    Posts
    19

    Re: Calculating days, hours, min, and sec between two dates excluding weekends

    NETWORKDAYS returns the number of WHOLE working days between two dates where your elapsed time calculation is taking into account the start and end times. There are 8 days Wed. to Wed. and taking out 2 weekend days leaves 6 whole days.

    To get what you are looking for you would have to adjust your Elapsed Time (d:h) formula to be

    Formula: copy to clipboard
    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    06-18-2020
    Location
    Arizona
    MS-Off Ver
    Office 365
    Posts
    75

    Re: Calculating days, hours, min, and sec between two dates excluding weekends

    Quote Originally Posted by Crystalyzer View Post
    NETWORKDAYS returns the number of WHOLE working days between two dates where your elapsed time calculation is taking into account the start and end times. There are 8 days Wed. to Wed. and taking out 2 weekend days leaves 6 whole days.

    To get what you are looking for you would have to adjust your Elapsed Time (d:h) formula to be

    Formula: copy to clipboard
    Please Login or Register  to view this content.
    I don't think this is working as intended, for example the Elapsed Time in the first row when converted to hh:mm:ss does not show less 48:00:00 with your updated formula. The original elapsed time is 60:41:53, minus 48:00:00 (Sat and Sunday hours = 48h), should be 12:41:53. Shouldn't the corrected formula show that too?

    Appreciate the help!
    Last edited by cph020283; 08-09-2021 at 03:45 PM.

  5. #5
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2403
    Posts
    13,406

    Re: Calculating days, hours, min, and sec between two dates excluding weekends

    What if you tried this:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Edited }I failed to mention that this 're-purposes' NETWORKDAYS.INTL count the weekends in order to subtract them from the Modified-Created differences.

    It returns this:


    1.53
    1.67
    1.35
    1.64
    1.74
    1.64
    3.35
    3.92
    4.95
    3.95
    3.18
    5.01
    6.85
    6.17
    Last edited by FlameRetired; 08-09-2021 at 04:44 PM.

  6. #6
    Registered User
    Join Date
    06-18-2020
    Location
    Arizona
    MS-Off Ver
    Office 365
    Posts
    75

    Re: Calculating days, hours, min, and sec between two dates excluding weekends

    Quote Originally Posted by FlameRetired View Post
    What if you tried this:
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    It returns this:


    1.53
    1.67
    1.35
    1.64
    1.74
    1.64
    3.35
    3.92
    4.95
    3.95
    3.18
    5.01
    6.85
    6.17
    This works! Wow, I didn't think it would be as simple as that, but it is! Thank you for lending your brains!

  7. #7
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2403
    Posts
    13,406

    Re: Calculating days, hours, min, and sec between two dates excluding weekends

    You are welcome. Thank you for the feedback, the added rep and marking your thread Solved.

  8. #8
    Registered User
    Join Date
    06-18-2020
    Location
    Arizona
    MS-Off Ver
    Office 365
    Posts
    75

    Re: Calculating days, hours, min, and sec between two dates excluding weekends

    Quote Originally Posted by FlameRetired View Post
    You are welcome. Thank you for the feedback, the added rep and marking your thread Solved.
    As it turns out this was working until I was looking at much larger differences in time.

    For example, as you'll see I've highlighted a few examples in the file that shows the elapsed time as 17 days vs the working days being 50, or in some cases 130+. The formula provided originally was:
    Attached Files Attached Files

  9. #9
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2403
    Posts
    13,406

    Re: Calculating days, hours, min, and sec between two dates excluding weekends

    Since there was no formula under 'Working ... ' I cannot tell. But it does appear you are mixing units. Your formula in 'Elapsed time' is calculating days, hours and minutes. The formatting is consistent with that. I don't know how you derived 'Working' but the formatting is General.

    My "instincts" tell me you tried to subtract 2 days from 134.+++ hours ..... that would be where the 132 came from.

  10. #10
    Registered User
    Join Date
    06-18-2020
    Location
    Arizona
    MS-Off Ver
    Office 365
    Posts
    75

    Re: Calculating days, hours, min, and sec between two dates excluding weekends

    Quote Originally Posted by FlameRetired View Post
    Since there was no formula under 'Working ... ' I cannot tell. But it does appear you are mixing units. Your formula in 'Elapsed time' is calculating days, hours and minutes. The formatting is consistent with that. I don't know how you derived 'Working' but the formatting is General.

    My "instincts" tell me you tried to subtract 2 days from 134.+++ hours ..... that would be where the 132 came from.
    Oops! I added the NETWORKDAYS() formula to the 'Working Days' column which derives that result. In the highlighted rows the 'Created On' and 'Closed On' dates are several months apart which is why NETWORKDAYS() provides a total of 132 working days between those two dates. Why the calculation for 'Elapsed Time' is only providing 13 days is what is I'm hoping to answer.
    Attached Files Attached Files

  11. #11
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2403
    Posts
    13,406

    Re: Calculating days, hours, min, and sec between two dates excluding weekends

    That's because NETWORKDAYS returns the number of days. The reason 'Elapsed time' returns days and times is due to subtracting the dates and times and the formatting.

    And BTW I really encourage the use of NETWORKDAYS.INTL. It is far more versatile (as is WORKDAY.INTL). You then add the times back in.

    That said try this formula in K5
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Custom format d.hh:mm:ss

    Row 13 now returns 11.20:32:30

    Is that what you were looking for?
    Last edited by FlameRetired; 08-10-2021 at 10:09 PM.

  12. #12
    Registered User
    Join Date
    06-18-2020
    Location
    Arizona
    MS-Off Ver
    Office 365
    Posts
    75

    Re: Calculating days, hours, min, and sec between two dates excluding weekends

    Quote Originally Posted by FlameRetired View Post
    That's because NETWORKDAYS returns the number of days. The reason 'Elapsed time' returns days and times is due to subtracting the dates and times and the formatting.

    And BTW I really encourage the use of NETWORKDAYS.INTL. It is far more versatile (as is WORKDAY.INTL). You then add the times back in.

    That said try this formula in K5
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Custom format d.hh:mm:ss
    Definitely will use NETWORKDAY.INTL() going forward! When trying your updated formula I am receiving the same result as before - there is a significantly less amount of days (I inserted your formula in H). I am trying to get the precise days, hours, minutes, and seconds minus the weekends. It seems to fall apart with larger distances between the two dates.
    Attached Files Attached Files

  13. #13
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2403
    Posts
    13,406

    Re: Calculating days, hours, min, and sec between two dates excluding weekends

    Arrgghhh!

    I forgot. There's a limitation on Custom formatting of days. Number of days returned top out at 31 days and then 'wrap around' starting over again at 1.

    This came up a few years back and I do not recall if there is a work-around for it except to concatenate the days and times. This renders the results text and useless for calculations.

    Like this:
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    In the meantime I'll put out a call for community help.

    Edit I just did that. May take a while.
    Last edited by FlameRetired; 08-10-2021 at 10:48 PM.

  14. #14
    Registered User
    Join Date
    06-18-2020
    Location
    Arizona
    MS-Off Ver
    Office 365
    Posts
    75

    Re: Calculating days, hours, min, and sec between two dates excluding weekends

    Quote Originally Posted by FlameRetired View Post
    Arrgghhh!

    I forgot. There's a limitation on Custom formatting of days. Number of days returned top out at 31 days and then 'wrap around' starting over again at 1.

    This came up a few years back and I do not recall if there is a work-around for it except to concatenate the days and times. This renders the results text and useless for calculations.

    Like this:
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    In the meantime I'll put out a call for community help.

    Edit I just did that. May take a while.
    Appreciate you going the extra mile!

    I borrowed your idea and took it a little bit further and found it works for all days where the case was not created or closed (or both) on the weekend. For the cases that were closed/opened--or both--on the weekend I realize I'd have to build conditional statements around these:

    Starts on a Saturday, ends on a week day
    Starts on a Sunday, ends on a week day
    Starts on a Saturday, ends on a Sunday
    Starts on a Sunday, ends on a Saturday
    Starts on a week day ends on a Saturday
    Starts on a week day ends on a Sunday


    Please Login or Register  to view this content.
    I'm sure there's a simpler way to solution this as I tend to make these things more complicated than they need to be!
    Last edited by cph020283; 08-11-2021 at 10:04 AM.

  15. #15
    Forum Guru Bo_Ry's Avatar
    Join Date
    09-10-2018
    Location
    Thailand
    MS-Off Ver
    MS 365
    Posts
    7,211

    Re: Calculating days, hours, min, and sec between two dates excluding weekends

    Starts on a Saturday, ends on a week day
    Starts on a Sunday, ends on a week day
    Starts on a Saturday, ends on a Sunday
    Starts on a Sunday, ends on a Saturday
    Starts on a week day ends on a Saturday
    Starts on a week day ends on a Sunday

    IF weekend is Sat and Sun, row 5 result should be 5 days 2 hours

    =CONCAT(TRIM(LEFT(SUBSTITUTE(TEXT(NETWORKDAYS(D5,E5,Table296)-SUM(MOD(D5:E5*{1,-1},1)*NETWORKDAYS(+D5:E5,+D5:E5,Table296)),{"0.0","hh:mm:ss"}),".","."&REPT(" ",9)),9)))
    Attached Files Attached Files
    Last edited by Bo_Ry; 08-11-2021 at 02:31 PM.

  16. #16
    Registered User
    Join Date
    06-18-2020
    Location
    Arizona
    MS-Off Ver
    Office 365
    Posts
    75

    Re: Calculating days, hours, min, and sec between two dates excluding weekends

    I brute-forced the solution to work under 4 conditionals.

    Combined IFS formula:
    Please Login or Register  to view this content.
    Conditionals used that were combined into the IFS:

    Please Login or Register  to view this content.

  17. #17
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,464

    Re: Calculating days, hours, min, and sec between two dates excluding weekends

    Created date is Sunday:
    18-Jul 10:21 AM, do you need it counted from 0:00 next Monday: 19-Jul 00:00 (With 13h39m deducted)? or same time of next working day, 19-Jul 10:21AM?

    Closed on Sat:
    17-Jul 9:00 PM, do you need it to be previous working day Fri 16-Jul 23:59:59 (With 9h deducted)? or same time of previous working day Fri 16-Jul 9:00 PM?
    Quang PT

+ 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. Replies: 9
    Last Post: 05-18-2021, 05:45 AM
  2. [SOLVED] Count working days excluding Weekend
    By babychai in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 05-17-2020, 02:06 PM
  3. [SOLVED] Calculating Years, Months, Week, Days, Hours, Minutes for Work Days between two dates
    By hecgroups in forum Excel Formulas & Functions
    Replies: 11
    Last Post: 08-23-2019, 12:09 AM
  4. Replies: 0
    Last Post: 10-31-2014, 10:32 AM
  5. Replies: 0
    Last Post: 04-07-2011, 01:46 AM
  6. highlight in red if over 3 days excluding weekend
    By unley in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 07-21-2010, 11:48 PM
  7. Due date excluding weekend days
    By Jfilbig in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 02-05-2006, 02:50 PM

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