+ Reply to Thread
Results 1 to 7 of 7

Days & Hours B/t Two Dates & Times

  1. #1
    Registered User
    Join Date
    07-23-2008
    Location
    Long Island
    Posts
    23

    Days & Hours B/t Two Dates & Times

    Hey,

    I can’t figure out why this formula is not working. I am trying to alter it a little, but I still think it should work. Here is what I am trying to do. I am looking to calculate the time difference between two work projects, but exclude time when the office is closed. So someone starts a project at 2pm and finish 10am the next day it will show a result of 4 hours because the office closes at 5.

    Here is the formula. It is the time formula from cpearson.com. http://www.cpearson.com/excel/DateTimeWS.htm

    =IF(AND(INT(D1)=INT(D2),NOT(ISNA(MATCH(INT(D1),HolidayList,0)))),0,ABS(IF(INT(D1)=INT(D2),ROUND(24*(D2-D1),2),(24*(DayEnd-DayStart)*(MAX(NETWORKDAYS(D1+1,D2-1,HolidayList),0)+INT(24*(((D2-INT(D2))-(D1-INT(D1)))+(DayEnd-DayStart))/(24*(DayEnd-DayStart))))+MOD(ROUND(((24*(D2-INT(D2)))-24*DayStart)+(24*DayEnd-(24*(D1-INT(D1)))),2),ROUND((24*(DayEnd-DayStart)),2))))))

    D1 is the start time of the first project. (ex: 7/4/2008 7:40:35)*
    D2 is the start of the second project & I am using that as the end time of the first project. (7/4/2008 13:01:16)*
    DayEnd is the time the office closes.
    DayStart is the time the office opens.
    *Dates in dd/mm/yyyy format.

    All my results come up as zeros, regardless of how I format the cells. I would think that this formula would be able to count down to the minute.

    Also, has anyone ever included break times using this formula? I would like to add that in, but I haven’t really focused on it yet.

    Any suggestions, ideas will be much appreciated.
    Last edited by oldchippy; 10-27-2008 at 12:04 PM.

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464
    Hi,

    It's perhaps stating the obvious, but have you got the Analysis Tool Pack add in installed so that the NETWORKDAYS() function can be used, as Chip mentions?

    In addition does your working day straddle midnight. He also says that would not give the right result, and do you have the 'HolidayList' set up?

    HTH

  3. #3
    Registered User
    Join Date
    07-23-2008
    Location
    Long Island
    Posts
    23
    I do have the analysis pack installed and my holiday list setup. My end of day is 11:59pm. I think this is the issue. I think I'll have try something different being I have too many entries to exclude the 11pm data.

    Thanks for the help.

  4. #4
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    Microsoft 365
    Posts
    14,721
    Chip's formula should work OK but you don't really need that huge formula, this would suffice

    =(NETWORKDAYS(D1,D2,HolidayList)-1)*(DayEnd-Daystart)+MOD(D2,1)-MOD(D1,1)

    result cell should be formatted as [h]:mm

    Both this formula and Chip's only work correctly where both D1 and D2 are within work hours, you can cater for start and end outside work hours too but you need a more complex formula

    See this thread for more. The formula posted by Kolacube [which is mine from another thread] is a version of the above catering for lunch breaks, my reply contains a further amendment to cater for start and finish time to be outside work hours

  5. #5
    Registered User
    Join Date
    07-23-2008
    Location
    Long Island
    Posts
    23
    Daddylong legs, thank you so much. Been trying to get this to work for days.

  6. #6
    Registered User
    Join Date
    07-23-2008
    Location
    Long Island
    Posts
    23
    Can a moderator please mark thread as solved? Thank you.

  7. #7
    Registered User
    Join Date
    05-27-2009
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    1

    Re: Days & Hours B/t Two Dates & Times

    Thank you for the furmula. It was the most simple one made for the most complicated.

+ 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