+ Reply to Thread
Results 1 to 5 of 5

Calculating between to time ranges

  1. #1
    Registered User
    Join Date
    10-11-2015
    Location
    Wpg, MB
    MS-Off Ver
    Excel 2010
    Posts
    34

    Calculating between to time ranges

    Hello All,

    I need some help. I am trying to calculate between to times i.e. 12:00 am to 1:00 pm and I keep getting .98 as the outcome when it should be 1.0. The formula I am using is =INT(((C9-C8)+(C11-C10))*1440)/60. It works for all calculations except when it comes to anything between 12:00 am and 1:00 pm. What am I doing wrong?

    You help is greatly appreciated.

    Thanks

  2. #2
    Valued Forum Contributor
    Join Date
    02-06-2013
    Location
    Germany
    MS-Off Ver
    365
    Posts
    491

    Re: Calculating between to time ranges

    It may have to do with Excel's maximum precision or floating point arithmetic.

    1 hour = 1/24 = 0.041666666666666...
    So since Excel has a finite amount of precision, 24 times the above would not equal 1, i.e. a full day.

    If you calculate differences between hours, you will notice that:
    For all hours until noon, the difference as a decimal is: 0.0416666666666667
    While for all hours thereafter until midnight, the difference as a decimal is: 0.0416666666666666

    Since I don't know what's happening in your cells C11 and C10, but I suspect the difference is zero, you end up truncating something to 59 minutes, which gets you 0.98.

    Instead of INT, better wrap around a round function with sufficient precions, say 10.

    =ROUND(((T27-T26)+(T29-T28))*1440,10)/60

  3. #3
    Registered User
    Join Date
    10-11-2015
    Location
    Wpg, MB
    MS-Off Ver
    Excel 2010
    Posts
    34

    Re: Calculating between to time ranges

    Thank you. I will give this a try.

  4. #4
    Valued Forum Contributor
    Join Date
    07-13-2021
    Location
    California, USA
    MS-Off Ver
    2010
    Posts
    513

    Re: Calculating between to time ranges

    @RBK2.... We don't know what values are in C8:C11. Based on your expectation, I assume that C8 and C9 are the same date, and C10 and C11 are times that are 1 hour apart.

    But the key is: how are the values in C10 and C11 derived?

    I see no error if we manually enter two times, for example 1:01 AM and 2:01 AM.

    So I assume, for example, that C6 is 10/17/2021 1:01 AM and C7 is 10/17/2021 2:01 AM, and the formulas in C8:C11 are:

    C8: =INT(C6)
    C9: =INT(C7)
    C10: =MOD(C6,1)
    C11: =MOD(C7,1)

    Then, your INT formula does indeed return 0.983333333333333 (+ 3.33E-16) for my example.

    Since you want integer minutes (divided by 60), you should do the following:

    =ROUND((C9-C8+C11-C10)*1440,0)/60

    -----

    Note.... Round to zero decimal places because that is the precision that you want (duh!).

    Do not round to an arbitrary number of decimal places like 10, because that might not always work.

    In fact, for my example, ROUND((C9-C8+C11-C10)*1440,10)/60 returns 0.999999999941667 (- 3.33E-16), not exactly 1 as you want.

    -----

    PS.... This is not limited to times "between" 12:00 AM and 1:00 PM. I get the same result when the times in C6 and C7 are 1:01 PM and 2:01 PM.

    So if you still have questions, please follow the instructions at the top of the webpage to attach an Excel file that demonstrates the problem, with appropriate formulas and data.
    Last edited by curiouscat408; 10-17-2021 at 06:01 PM. Reason: minor typos

  5. #5
    Registered User
    Join Date
    10-11-2015
    Location
    Wpg, MB
    MS-Off Ver
    Excel 2010
    Posts
    34

    Re: Calculating between to time ranges

    Thank you!!! I tried it with ,10 and in some cases it did not work. So I changed it to ,0 and it appears to now be working.

    THANK YOU!

+ 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. Calculating the $'s between two date ranges
    By HJHamm in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 04-21-2015, 07:49 AM
  2. Calculating how many Days and Hour between two date/time ranges.
    By valhallaone in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 05-13-2014, 04:36 PM
  3. Calculating usage over time ranges
    By njmike in forum Excel Charting & Pivots
    Replies: 4
    Last Post: 04-09-2014, 10:28 AM
  4. Calculating Time Overlaps with Multiple Ranges
    By LAMFCU in forum Excel General
    Replies: 3
    Last Post: 07-03-2013, 04:40 AM
  5. [SOLVED] Calculating Min using variable ranges in VBA
    By M Knowling in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-06-2012, 11:00 PM
  6. Replies: 3
    Last Post: 11-21-2012, 05:47 AM
  7. Calculating times ranges
    By troublewithexcel in forum Excel General
    Replies: 11
    Last Post: 06-02-2011, 09:22 AM

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