+ Reply to Thread
Results 1 to 14 of 14

Difference between 2 dates - excluding working hours, weekends and holidays

  1. #1
    Registered User
    Join Date
    03-23-2011
    Location
    Ontario
    MS-Off Ver
    Excel 2007
    Posts
    3

    Exclamation Difference between 2 dates - excluding working hours, weekends and holidays

    Hi,

    I am trying to write an excel formula that will calculate the time difference (hours and minutes) between two dates (the time a ticket was opened and the time it was closed), taking into consideration only working hours (8:30 am - 5 pm) and excluding weekends and holidays.
    For example:
    Ticket opened on : Friday Mar 4 2011 4:00 pm
    Ticket closed on : Tuesday Mar 8 2011 9:00 pm
    Holiday ex: Mon Mar 7 2011

    Then the answer should be: 1.5 hours

    I am aware of NETWORKDAYS formula which handles weekends, any help is appreciated in adding to the formula to count for business hours and exclude holiday days (I suppose the holidays are to be stored seperately in the sheet).

    Thank you.
    Ray

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,167

    Re: Difference between 2 dates - excluding working hours, weekends and holidays

    Hi ray2 and welcome to the forum.

    BTW - I think you meant 9AM when presenting your problem.

    With A1 = Ticket Open date and Time and
    with B1 = Ticket Closed date and time (make that 9am and not 9pm)
    in C1 put this formula for the total number of hours.
    Please Login or Register  to view this content.
    So here is the reasoning.
    Ticket opens during business hours. So hours on Open Date = 5pm - open time or
    Please Login or Register  to view this content.
    Similarly hours on Closed Ticket day is when it closed - start of work or 8:30 (8.5)
    Please Login or Register  to view this content.
    Then we use NetWorkDays between the two dates but subtract two since we used them above.
    We also throw in the holiday, in text format or
    Please Login or Register  to view this content.
    But we have to multiply the full number of workdays by work hours or 8.5 hours a day.

    These three parts roll into the single equation above in C3.

    You would have to change the holidays or hours worked per day for different problems

    hope this does it for you.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Difference between 2 dates - excluding working hours, weekends and holidays

    Below formulas are c/o resident date guru Daddylonglegs:

    Please Login or Register  to view this content.
    References are as follows:

    A2: start datetime
    B2: end datetime
    H1:H10 list of public holiday dates

  4. #4
    Registered User
    Join Date
    03-23-2011
    Location
    Ontario
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Difference between 2 dates - excluding working hours, weekends and holidays

    thank you so much for the replies!! I will try it and advice back.

  5. #5
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,167

    Re: Difference between 2 dates - excluding working hours, weekends and holidays

    @DO (and @DLL?)
    I have to live up to my signature and do a test.

    What did I do wrong?

    Ok - I got my money messed up in the wrong cells. Now it looks like it works in second attach.
    Attached Files Attached Files
    Last edited by MarvinP; 03-24-2011 at 12:43 PM. Reason: Wrong Cell Ref - got it

  6. #6
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Difference between 2 dates - excluding working hours, weekends and holidays

    @ray2, I should have added that you should format the resulting cell with custom format of: [h]:mm
    (else * 24 and format as number if you prefer decimal hours)

    These calculations are often complex and invariably daddylonglegs has resolved similar (if not identical) problems at some point in the past ... as robustly / elegantly as is possible with native functions (as illustrated here).

  7. #7
    Registered User
    Join Date
    03-23-2011
    Location
    Ontario
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Difference between 2 dates - excluding working hours, weekends and holidays

    Thank you MarvinP and DonkeyOte i tried it and it works like magic!

  8. #8
    Registered User
    Join Date
    03-25-2011
    Location
    Rhode Island
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Difference between 2 dates - excluding working hours, weekends and holidays

    *** Disregard, after some modifications and separation, I reused DonkeyOte's formula without error. Thank you!! UE can be a bear.

    I tried to modify the formulas from MarvinP and DonkeyOte to no avail.

    I have two dates (1/11/11 5:11 PM and 1/12/11 11:08 AM) and I have a workday of 8am to 6pm and I need to determine the number of work hours between them. Subtracting potential holidays would be a bonus. When I make the changes to the formulas posted (my cells are P24 and R24) I get inconsistent formula and incorrect values like 1/0/00 3:57:00 or 55:37 hours when I should get 3:57. Perhaps I'm substituting something incorrectly, but it seems fairly straightforward, so its most likely "UE."

    Any help would be greatly appreciated!

    Regards,
    Jimmy
    Last edited by jimmy37; 04-01-2011 at 02:50 PM.

  9. #9
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Difference between 2 dates - excluding working hours, weekends and holidays

    Quote Originally Posted by jimmy37 View Post
    *** Disregard, after some modifications and separation, I reused DonkeyOte's formula without error. Thank you!!
    That's good news ... going forward please do not ask questions in the thread of another member - create your own and post a link back to the original for reference.

  10. #10
    Registered User
    Join Date
    09-14-2012
    Location
    india
    MS-Off Ver
    Excel 2003
    Posts
    3

    Need help

    a b c d e f g h 1
    Start Date End Date Elapse time 1st Shift Start 1st Shift End 2nd Shift Start 2nd Shift End DayOff 1 DayOff2
    10:00 AM 10:00 PM 12:00 9:00 AM 12:00 PM 1:00 PM 6:00 PM Monday Tuesday

    J
    Actual Service Interruption Hours
    (Trying to find a formula to calculate the Actual Service Interruption Hours from Above scenario)


    Thanks

  11. #11
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Difference between 2 dates - excluding working hours, weekends and holidays

    Sajid45,

    Welcome to the Forum, unfortunately:

    Your post does not comply with Rule 2 of our Forum RULES. Don't post a question in the thread of another member -- start your own thread. If you feel it's particularly relevant, provide a link to the other thread. It makes sense to have a new thread for your question because a thread with numerous replies can be off putting & difficult to pick out relevant replies.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  12. #12
    Registered User
    Join Date
    11-25-2013
    Location
    india
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: Difference between 2 dates - excluding working hours, weekends and holidays

    sir, if there is any holiday in the opening and closed date , how can the time wil be removed from total?

  13. #13
    Registered User
    Join Date
    12-19-2010
    Location
    mumbai, India
    MS-Off Ver
    Excel 2003
    Posts
    71

    Re: Difference between 2 dates - excluding working hours, weekends and holidays

    Hi Everyone,

    I have similar query.

    my working starts with 7:00 AM in the morning and closes at 3:30 AM in the next morning (20.5 Hrs) monday to Friday.

    I want a formula that will calculate time difference between to datetime stapms in A1 and B1 respectively.

    A1: Ticket opened
    B1: Ticket closed time

    It should exclude weekends (Sat and Sun)

    Thnaks.

  14. #14
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,598

    Re: Difference between 2 dates - excluding working hours, weekends and holidays

    saurabhlotankar,
    Unfortunately your post does not comply with Rule 2 of our Forum RULES. Do not post a question in the thread of another member -- start your own thread.

    If you feel an existing thread is particularly relevant to your need, provide a link to the other thread in your new thread.

    Old threads are often only monitored by the original participants. New threads not only open you up to all possible participants again, they typically get faster response, too.
    Ben Van Johnson

+ 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