+ Reply to Thread
Results 1 to 18 of 18

how to calculate the difference between two dates&time within certain hours

  1. #1
    Registered User
    Join Date
    01-05-2020
    Location
    Malaysia
    MS-Off Ver
    MS office 2016
    Posts
    10

    how to calculate the difference between two dates&time within certain hours

    Hi There,

    My question as follows;

    1. Open date: 1/2/2010 5:22pm
    2. Closed date : 2/2/2010 2:22pm

    Hours to exclude in the calculation is 12am till 6am

    Basically, i am trying to calculate the time difference in hours between Open date and Closed date and excluding 12am till 6am.

    Answer should be (if i calculated it correctly): 13hours and 54 minutes.

    Thanks in advance

  2. #2
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284

    Re: how to calculate the difference between two dates&time within certain hours

    I don't get why it is 13:54, looks like 15:00 difference to me.

  3. #3
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284

    Re: how to calculate the difference between two dates&time within certain hours

    If I am correct, you can use

    =MAX(0,NETWORKDAYS(A2,A3)*("24:00"-"06:00")
    -IF(NETWORKDAYS(A2,A2),(MEDIAN(MOD(A2,1),"24:00","06:00")-"06:00"),0)
    -IF(NETWORKDAYS(A3,A3),("24:00"-MEDIAN(MOD(A3,1),"24:00","06:00")),0))

  4. #4
    Registered User
    Join Date
    01-05-2020
    Location
    Malaysia
    MS-Off Ver
    MS office 2016
    Posts
    10

    Re: how to calculate the difference between two dates&time within certain hours

    Quote Originally Posted by Bob Phillips View Post
    I don't get why it is 13:54, looks like 15:00 difference to me.
    Ooppps i may have calculated it incorrectly. my bad.

  5. #5
    Registered User
    Join Date
    01-05-2020
    Location
    Malaysia
    MS-Off Ver
    MS office 2016
    Posts
    10

    Re: how to calculate the difference between two dates&time within certain hours

    Thank you..

    I've updated the formula to my sheet

    "=MAX(0,NETWORKDAYS(I8,J8)*("24:00"-"06:00")
    -IF(NETWORKDAYS(I8,I8),(MEDIAN(MOD(I8,1),"24:00","06:00")-"06:00"),0)
    -IF(NETWORKDAYS(J8,J8),("24:00"-MEDIAN(MOD(J8,1),"24:00","06:00")),0))"

    I8 = 14/12/2019 10:30 PM
    J8 = 15/12/2019 01:32 PM

    Doesn't networkdays exclude weekends? if yes, i need to include that as well. The only thing to exclude in the calculation is the hours from 12am to 6am.
    Last edited by AliGW; 01-05-2020 at 01:13 PM. Reason: Please don't quote unnecessarily!

  6. #6
    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

    Re: how to calculate the difference between two dates&time within certain hours

    Is there only ever a maximum of one day difference between Open & Close dates or could the gap be several days?
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  7. #7
    Registered User
    Join Date
    01-05-2020
    Location
    Malaysia
    MS-Off Ver
    MS office 2016
    Posts
    10

    Re: how to calculate the difference between two dates&time within certain hours

    The gap between the days could be a day or several days apart and it could also be on the days itself. Example, open 1/1/2010 at 10am and closed on 1/1/2010 at 3pm.
    Last edited by AliGW; 01-05-2020 at 01:12 PM. Reason: Please don't quote unnecessarily!

  8. #8
    Registered User
    Join Date
    01-04-2020
    Location
    Hull, UK
    MS-Off Ver
    2016
    Posts
    60

    Re: how to calculate the difference between two dates&time within certain hours

    Here's a UDF that will do what you want...

    Please Login or Register  to view this content.
    Use it in a cell and format it as "[h]:mm"
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    01-05-2020
    Location
    Malaysia
    MS-Off Ver
    MS office 2016
    Posts
    10

    Re: how to calculate the difference between two dates&time within certain hours

    Quote Originally Posted by juddaaaa View Post
    Here's a UDF that will do what you want...

    Please Login or Register  to view this content.
    Use it in a cell and format it as "[h]:mm"
    wow this is awesome. and thanks a bunch.. i'll give it a try and report back

  10. #10
    Registered User
    Join Date
    01-05-2020
    Location
    Malaysia
    MS-Off Ver
    MS office 2016
    Posts
    10

    Re: how to calculate the difference between two dates&time within certain hours

    Quote Originally Posted by juddaaaa View Post
    Here's a UDF that will do what you want...

    Please Login or Register  to view this content.
    Use it in a cell and format it as "[h]:mm"
    It works Juddaaaa - thank you very much !!!!!

  11. #11
    Registered User
    Join Date
    01-05-2020
    Location
    Malaysia
    MS-Off Ver
    MS office 2016
    Posts
    10

    Re: how to calculate the difference between two dates&time within certain hours

    hi juddaaaa

    The UDF works but if gives me ########## when the close date falls within 12am to 6am...

    Open: 11/12/2019 22:53
    Close: 12/12/2019 4:51

    I noticed that all those closed within 12am to 6am is giving me the ######## (message is dates and times that are negative or too large to show as #####

    the answer should be 1.07, right?

  12. #12
    Registered User
    Join Date
    01-04-2020
    Location
    Hull, UK
    MS-Off Ver
    2016
    Posts
    60

    Re: how to calculate the difference between two dates&time within certain hours

    Try this

    Please Login or Register  to view this content.
    Last edited by juddaaaa; 01-06-2020 at 07:30 PM.

  13. #13
    Registered User
    Join Date
    01-05-2020
    Location
    Malaysia
    MS-Off Ver
    MS office 2016
    Posts
    10

    Re: how to calculate the difference between two dates&time within certain hours

    Quote Originally Posted by juddaaaa View Post
    Try this

    Please Login or Register  to view this content.
    Thanks again!!!

    I've noticed, if the open time falls within 12am to 6am, the calculation will include the hours within 12am to 6am.

    example,
    open 7/12/2019 2:43am
    close 7/12/2019 9:28am
    answer = 6:45

    This happens if the open date is within 12am to 6am. if it was outside those hours, the calculation is perfect.

    By the way, can we change reading from 6:45 to 6.45?

  14. #14
    Registered User
    Join Date
    01-04-2020
    Location
    Hull, UK
    MS-Off Ver
    2016
    Posts
    60

    Re: how to calculate the difference between two dates&time within certain hours

    This should do it

    Please Login or Register  to view this content.
    Open = 7/12/2019 2:43am
    Closed 7/12/2019 9:28am

    Answer = 3.28

    To get 3.28 change the format of the cell from [h]:mm to [h].mm
    Last edited by juddaaaa; 01-07-2020 at 09:23 PM.

  15. #15
    Registered User
    Join Date
    01-05-2020
    Location
    Malaysia
    MS-Off Ver
    MS office 2016
    Posts
    10

    Re: how to calculate the difference between two dates&time within certain hours

    Quote Originally Posted by juddaaaa View Post
    This should do it

    Please Login or Register  to view this content.
    Open = 7/12/2019 2:43am
    Closed 7/12/2019 9:28am

    Answer = 3.28

    To get 3.28 change the format of the cell from [h]:mm to [h].mm
    Awesome !! it works now.. thank you very much...

    POST can be changed to RESOLVED
    Last edited by Qhamzarul15; 01-08-2020 at 02:58 AM. Reason: update post

  16. #16
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2403
    Posts
    13,406

    Re: how to calculate the difference between two dates&time within certain hours

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

    Also, as a relatively new member of the forum, you may not be aware that you can thank those who have helped you by clicking the small star icon located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of those who helped.
    Dave

  17. #17
    Registered User
    Join Date
    01-05-2020
    Location
    Malaysia
    MS-Off Ver
    MS office 2016
    Posts
    10

    Re: how to calculate the difference between two dates&time within certain hours

    Thank you. I was wondering how to mark the thread as solve

  18. #18
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2403
    Posts
    13,406

    Re: how to calculate the difference between two dates&time within certain hours

    Quote Originally Posted by Qhamzarul15 View Post
    Thank you. I was wondering how to mark the thread as solve
    This is how you do that:
    please select Thread Tools from the menu link above and mark this thread as SOLVED.

+ 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. Calculate time difference based on working hours
    By stanlyj in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 03-31-2017, 08:39 AM
  2. Calculate the difference in hours between two dates?
    By Jonblomberg in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 12-14-2011, 09:42 AM
  3. Replies: 7
    Last Post: 01-11-2011, 06:26 AM
  4. [SOLVED] HOURS DIFFERENCE IN TIME BETWEEN DIFFERENT DATES AND TIMES
    By tankerman in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 09-13-2005, 12:05 PM
  5. [SOLVED] Calculate difference in time spanning a day, during office hours o
    By frozenfusion in forum Excel General
    Replies: 1
    Last Post: 08-26-2005, 06:05 AM
  6. [SOLVED] calculate difference in time to hours
    By Chris in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 01-18-2005, 03:06 PM
  7. [SOLVED] How do I calculate difference in days & hours between two dates e.
    By probi2 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 01-12-2005, 12:06 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