Closed Thread
Results 1 to 8 of 8

Calculate difference between two dates, in hours, excluding holidays/weekends

  1. #1
    Registered User
    Join Date
    05-23-2007
    Posts
    2

    Calculate difference between two dates, in hours, excluding holidays/weekends

    Can anyone help with this issue?


    I'm trying to calculate the # of hours between the two dates, excluding holidays and weekends, with the standard work day equal to 8am to 5pm.

    See the attached file for example. The highlighted cells should logically show 1.5 hours, but I always show 9 hours using network days.

    Any help is appreciated.
    Attached Files Attached Files
    Last edited by ut2282v; 05-23-2007 at 04:07 PM.

  2. #2
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675
    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
    Registered User
    Join Date
    05-23-2007
    Posts
    2
    This site rules!

    Works great, thank you!!!



  4. #4
    Registered User
    Join Date
    02-21-2007
    Posts
    6
    I'm looking to do something similar although I don't need a standard work day, just a day as a 24 hour period. I want to see if the time between the start date/time and end date/time is 72 hours or less, not counting weekends and holidays. It seems like it should be easy enough but clearly I'm missing something. I understand the networkdays part but the rest of the formula is eluding me.

  5. #5
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675
    If you just want to count total hours between start time/date and end time/date not including midnight Friday to midnight Sunday then you should be able to use

    =NETWORKDAYS(A2,B2)-1+MOD(B2,1)-MOD(A2,1)

    format as [h]:mm

    where A2 holds start time/date and B2 holds end time/date and both of these are NOT at the weekend

    If you just want a TRUE when the time difference is 72 hours or less, FALSE otherwise

    =NETWORKDAYS(A2,B2)-1+MOD(B2,1)-MOD(A2,1)<="72:00"+0

  6. #6
    Registered User
    Join Date
    02-21-2007
    Posts
    6
    That will work beautifully, thanks a lot. I was overthinking it and making it was more involved than it needed to be. Your solution has the advantage of being simple and working.

  7. #7
    Registered User
    Join Date
    01-11-2011
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: Calculate difference between two dates, in hours, excluding holidays/weekends

    Quote Originally Posted by daddylonglegs View Post
    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)
    Hello, in my case the start and end times of each day are not same i.e on one day i will come at 8.00 am in morning and leave at 5.00 pm, next day i will come at 9.00 am and leave at 6.30 pm, next day i will come at 8.00 am and leave at 4.30 pm then what will be the formula?
    Last edited by vinaynk24; 01-11-2011 at 06:09 AM. Reason: Correction in question.

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

    Re: Calculate difference between two dates, in hours, excluding holidays/weekends

    @vinaynk24, welcome to the board though please note per Forum Rules; do not post questions in the thread of another member.

    Create your own thread. If you feel another thread is particularly relevant provide a link to it from your own.

Closed 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