+ Reply to Thread
Results 1 to 23 of 23

How to Calculate duration in Excel Excluding Weekends and public holiday

  1. #1
    Registered User
    Join Date
    04-08-2016
    Location
    UAE
    MS-Off Ver
    2010
    Posts
    13

    Question How to Calculate duration in Excel Excluding Weekends and public holiday

    Below Excel formula works fine to find duration between two dates and times.It excludes weekends(Friday and Saturday) and Public holidays also.

    A1=12/27/2016 10:30:00 AM
    B1=12/29/2016 11:59:59 PM
    7= Exclude weekends(Friday and Saturday)
    B9:B10=Exclude Holidays mentioned on B9:B10

    =NETWORKDAYS.INTL(A1,B1,7,B9:B10)-1-MOD(A1,1)+MOD(B1,1)
    However I need to calculate duration where B1 is not given and i have to consider current date and and Time i-e B1=now(). I used below formula but it is not giving the correct result.

    =NETWORKDAYS.INTL(A1,NOW(),7,B9:B10)-1-MOD(A1,1)+MOD(NOW(),1)

    Any idea Pls.

  2. #2
    Banned User!
    Join Date
    10-29-2012
    Location
    Europe
    MS-Off Ver
    2013, 2016
    Posts
    318

    Re: How to Calculate duration in Excel Excluding Weekends and public holiday

    Change NOW() with TODAY() in your formula.

    =NETWORKDAYS.INTL(A1,TODAY(),7,B9:B10)-1-MOD(A1,1)+MOD(TODAY(),1)

    Or

    =NETWORKDAYS.INTL(A1;NOW(),7,B9:B10)-1-MOD(A1,1)+MOD(TODAY(),1)
    Last edited by Indi_Ra; 12-31-2016 at 07:54 AM.

  3. #3
    Registered User
    Join Date
    04-08-2016
    Location
    UAE
    MS-Off Ver
    2010
    Posts
    13

    Re: How to Calculate duration in Excel Excluding Weekends and public holiday

    Thanks for your response, It also not works as I need duration in Hours instead of Days

  4. #4
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 2019
    Posts
    17,548

    Re: How to Calculate duration in Excel Excluding Weekends and public holiday

    Try the following formula with the cell formatted to [h]:mm:ss;@ :
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Let us know if you have any questions.
    Last edited by JeteMc; 12-31-2016 at 01:14 PM. Reason: Correcting formula
    Consider taking the time to add to the reputation of everybody that has taken the time to respond to your query.

  5. #5
    Banned User!
    Join Date
    10-29-2012
    Location
    Europe
    MS-Off Ver
    2013, 2016
    Posts
    318

    Re: How to Calculate duration in Excel Excluding Weekends and public holiday

    Quote Originally Posted by muneeb567 View Post
    Thanks for your response, It also not works as I need duration in Hours instead of Days
    Then format cell: [h]:mm

  6. #6
    Registered User
    Join Date
    04-08-2016
    Location
    UAE
    MS-Off Ver
    2010
    Posts
    13

    Re: How to Calculate duration in Excel Excluding Weekends and public holiday

    Hi JeteMc,

    Seems fine as I tested on few samples dates.Thanks

  7. #7
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 2019
    Posts
    17,548

    Re: How to Calculate duration in Excel Excluding Weekends and public holiday

    I am glad to hear back and you are welcome. Please take a moment to mark the thread as 'Solved' using the thread tools link above your first post. I hope that you have a blessed day.

  8. #8
    Registered User
    Join Date
    04-08-2016
    Location
    UAE
    MS-Off Ver
    2010
    Posts
    13

    Re: How to Calculate duration in Excel Excluding Weekends and public holiday

    Hi JeteMC,

    based on further testing, this formula works fine if B1<>blank, as shown Below(FigA). However if B1= Blank then value is not correct as shown in fig B

    Fig A

    A1 B1 C1 D1 E1
    start date end date Correct Result(Days) Formula Result Comments
    27/12/2016 10:30 29/12/2016 23:59 2.56249 2.56249 Result matched ,OK

    Fig B
    start date end date Correct Result(Days) Formula Result Comments
    27/12/2016 10:30 2.56249 1.66829 D1 not matched with E1, Not OK

    pls note B9:B10 = 1/1/2017
    Last edited by muneeb567; 12-31-2016 at 06:34 PM.

  9. #9
    Registered User
    Join Date
    04-08-2016
    Location
    UAE
    MS-Off Ver
    2010
    Posts
    13

    Re: How to Calculate duration in Excel Excluding Weekends and public holiday

    Pls check and share the solution for 2nd case as well when B1=blank

  10. #10
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 2019
    Posts
    17,548

    Re: How to Calculate duration in Excel Excluding Weekends and public holiday

    If I understand correctly you are expecting an answer of 2.5625 when B1 is blank. The following formula provides that result:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Let us know if you have any questions.

  11. #11
    Registered User
    Join Date
    04-08-2016
    Location
    UAE
    MS-Off Ver
    2010
    Posts
    13

    Re: How to Calculate duration in Excel Excluding Weekends and public holiday

    Yes , Answer must be 2.5625 either B1 is blank or end date is =29/12/2016 23:59. Because in my formula Friday and Saturday are Weekends and 1/1/2017 is public holiday So B1 Is the Time ends on 29/12/2016 23:59:00.However This formula gives different answer when B1=blank even used the new formula.Can you pls check the attached image

    formula.jpg

  12. #12
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 2019
    Posts
    17,548

    Re: How to Calculate duration in Excel Excluding Weekends and public holiday

    The attached file has the formula applied to both E1 and E3. There is a value in B1 (12/27/2016 11:59:59) and B3 is empty, both E1 and E3 are displaying 2.5625
    Let us know if you have any questions.

  13. #13
    Registered User
    Join Date
    04-08-2016
    Location
    UAE
    MS-Off Ver
    2010
    Posts
    13

    Re: How to Calculate duration in Excel Excluding Weekends and public holiday

    Result is different even in our attached sheet As shown below
    formula-met.jpg...

    Very Strange.am i doing any mistakes ???

  14. #14
    Registered User
    Join Date
    04-08-2016
    Location
    UAE
    MS-Off Ver
    2010
    Posts
    13

    Re: How to Calculate duration in Excel Excluding Weekends and public holiday


  15. #15
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 2019
    Posts
    17,548

    Re: How to Calculate duration in Excel Excluding Weekends and public holiday

    It is my mistake and I apologize. Here is the way that the formula should be written to accommodate an empty cell in column B:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Let us know if you have any questions.

  16. #16
    Registered User
    Join Date
    04-08-2016
    Location
    UAE
    MS-Off Ver
    2010
    Posts
    13

    Re: How to Calculate duration in Excel Excluding Weekends and public holiday

    Thanks for your patience however when I checked with new End date/time, Result is again different. seems error in code when B1=blank,Pls check

  17. #17
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 2019
    Posts
    17,548

    Re: How to Calculate duration in Excel Excluding Weekends and public holiday

    When I opened the file attached to post #16 B3 read 3.5625, however as soon as I pressed the 'Enable Editing' button it changed to the expected 2.5625 to be honest I don't know what caused that behavior. When I open the file from my hard drive, the one attached to post #15, it displays 2.5625 I would encourage you to save the file from post #15 to your hard drive, close the spreadsheet then open it again and see what value is displayed when opened from your hard drive.
    Let us know if you have any questions.
    Edit: It just occurred to me that it is already Monday 1/2/17 in UAE so if B3 is blank the value will be different. You could test by putting the date 1/2/17 in B10 so that the formula should still only calculate the time from 10:30 am on the 27th through 11:59:59 on the 29th.
    Last edited by JeteMc; 01-01-2017 at 09:41 PM. Reason: Added Edit

  18. #18
    Registered User
    Join Date
    04-08-2016
    Location
    UAE
    MS-Off Ver
    2010
    Posts
    13

    Re: How to Calculate duration in Excel Excluding Weekends and public holiday

    I also used Post #15 excel file and just changed the B1 value=Now(), Result in E1 must be equal to E3.... But E3 is Showing almost 12 Hours more than E1. When I calculated Result manually ,Found E1 Is showing Correct result while E3 is providing incorrect result. It seems when End Time=blank then there is some error in formula.

  19. #19
    Registered User
    Join Date
    04-08-2016
    Location
    UAE
    MS-Off Ver
    2010
    Posts
    13

    Re: How to Calculate duration in Excel Excluding Weekends and public holiday

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

    I Made slight changes in your code and now it seems working fine even when B1=blank, in 2nd part of formula, I Replaced Today() with Now() and B1 with Now().Pls check and advise as till now it is giving correct results.
    Last edited by muneeb567; 01-02-2017 at 06:23 AM.

  20. #20
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 2019
    Posts
    17,548

    Re: How to Calculate duration in Excel Excluding Weekends and public holiday

    I made two changes. In the part of the formula where the COUNTIFS functions are comparing the list of holidays to the present date, I changed NOW() to TODAY(). The reason being that the dates in the list of holidays do not have decimal parts so comparing them to NOW() would always yield a result of zero.
    Seems to me that your formula, with the changes applied as shown below, yields the correct results.
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Let us know if you have any questions.

  21. #21
    Registered User
    Join Date
    04-08-2016
    Location
    UAE
    MS-Off Ver
    2010
    Posts
    13

    Re: How to Calculate duration in Excel Excluding Weekends and public holiday

    Thanks Jet for your cooperation, I found the required formula with your utmost effort. Cheers

  22. #22
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 2019
    Posts
    17,548

    Re: How to Calculate duration in Excel Excluding Weekends and public holiday

    Looking back I think that I over complicated the portion of the formula that calculates elapsed time when an end date is present. I guess in the spirit of 'if it ain't broke don't fix it' we could just leave 'well enough alone', however I wanted to point it out. The simplification would require the assumption that the end date would not fall on a Friday, Saturday nor holiday. If that assumption is correct you may want to test the following:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    I hope that you have a blessed day.

  23. #23
    Registered User
    Join Date
    04-08-2016
    Location
    UAE
    MS-Off Ver
    2010
    Posts
    13

    Re: How to Calculate duration in Excel Excluding Weekends and public holiday

    You are right JeteMc, this code seems correct and even short w.r.t previous one.thanks for your precious time.

+ 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. Formula for SLA by excluding weekends (Fri & Sat) & Holiday
    By Ankit_Kumar in forum Excel General
    Replies: 3
    Last Post: 06-11-2015, 03:22 AM
  2. Formula for SLA by excluding non-business hours, weekends (Fri & Sat) & Holiday
    By dhiraj4mann in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 03-03-2015, 04:26 AM
  3. [SOLVED] Counting working days excluding holiday and weekends
    By thollander in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 06-20-2014, 11:28 AM
  4. Date/Time Calculation excluding weekends and holiday list not working
    By mikeyk80 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 07-31-2012, 10:39 AM
  5. [SOLVED] Calculate duration exclude weekends
    By pyrofenix in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 07-18-2011, 02:34 PM
  6. Difference in Days Excluding Saturday and Public Holiday
    By Kumara_faith in forum Excel General
    Replies: 19
    Last Post: 10-06-2010, 08:50 PM
  7. Replies: 3
    Last Post: 03-31-2008, 01:27 PM

Tags for this Thread

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