+ Reply to Thread
Results 1 to 7 of 7

Difference between two dates

  1. #1
    Registered User
    Join Date
    12-29-2010
    Location
    USA
    MS-Off Ver
    Excel 2003/2010
    Posts
    69

    Difference between two dates

    Help! I have two different sources of people trying to do the same as me, but neither appear to be working and I am at a lost for where I am going wrong.

    http://www.cpearson.com/excel/DateTimeWS.htm#WorkHours

    http://www.excelforum.com/excel-gene...-holidays.html

    I am trying to calculate the hours and minutes between two dates and times but only within business hours. The business hours are 8:00AM - 4:00PM. Using the first link there is an example workbook that I tried using. I put in 1/10/2013 11:03:43:PM as the received date, and 1/11/2013 8:26:14 AM as the completed date. When I plug these numbers into the sample workbook on the first link it spits out 6.12 hours. If we are only calculating business hours the start date would be 1/11/2013 8:00:00AM and it would be completed at the same time for a completion time or duration of 26 minutes and 14 seconds.

    In the second link and the download "TicketOpenAndClosedHours2.xlsx‎" I plug in the same date and time and it kicks out 6.02 for the duration.

    What am I missing? What am I doing wrong? Shouldn't these calculations result in a 26 minutes due to business hours?

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Difference between two dates

    Please Login or Register  to view this content.
    The formula in B8 is

    =(INT(B7) - INT(B6)) * ($B$3 - $B$2)
    + MEDIAN(MOD(B7, 1), $B$2, $B$3)
    - MEDIAN(MOD(B6, 1), $B$2, $B$3)


    The cell is formatted as [h]:mm:ss
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    12-29-2010
    Location
    USA
    MS-Off Ver
    Excel 2003/2010
    Posts
    69

    Re: Difference between two dates

    This works perfectly. I am very pleased with the formula. Unfortunately I am not pleased with the results. It turns out every weekend there are 16 hours of randomly worked time. Example is we received a date of 1/11/2013 3:41:30 PM, 19 minutes before close. It shouldn't be worked until 1/14/13 8:00:00 AM, instead it was worked on at 1/12/2013 9:44:57 PM. So can you think of a way to add in a clause that if completed date is a weekend and completed before Monday it isn't late or even results in a 2. Part one is finding the duration, part two is analyzing how many were completed in bucket intervals. I can take care of the bucket intervals if I didn't have this 16 hours of worked hours completing things outside of business hours.

  4. #4
    Registered User
    Join Date
    12-29-2010
    Location
    USA
    MS-Off Ver
    Excel 2003/2010
    Posts
    69

    Re: Difference between two dates

    Never mind I was able us IF(OR(Text(cell,"ddd"="Sat",Text(Cell,"ddd"="Sun),"02:00",your formula. Thank you for all of the help.

  5. #5
    Registered User
    Join Date
    12-29-2010
    Location
    USA
    MS-Off Ver
    Excel 2003/2010
    Posts
    69

    Re: Difference between two dates

    I did run into another problem I didn't realize this didn't work on the weekends (or I did something wrong).

    Please Login or Register  to view this content.
    Since it was received on Friday after 4:00PM, it shouldn't be in until 8:00AM on Monday (the 14th) so the time elapsed should be 4:26.

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Difference between two dates

    Please Login or Register  to view this content.
    From Daddylonglegs:

    = (NETWORKDAYS(B4, B5)-1) * ($B$2 - $B$1)
    + IF(NETWORKDAYS(B5, B5), MEDIAN(MOD(B5, 1), $B$2, $B$1), $B$2)
    - MEDIAN(NETWORKDAYS(B4, B4) * MOD(B4,1), $B$2, $B$1)

  7. #7
    Registered User
    Join Date
    12-29-2010
    Location
    USA
    MS-Off Ver
    Excel 2003/2010
    Posts
    69

    Re: Difference between two dates

    Works like a charm. Thank you

+ 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