+ Reply to Thread
Results 1 to 4 of 4

Random calculation error with adding and subtracting times

  1. #1
    Registered User
    Join Date
    09-02-2020
    Location
    Brussels
    MS-Off Ver
    Office 365
    Posts
    2

    Random calculation error with adding and subtracting times

    I have a staff timesheet which records overtime/undertime worked by a member of staff based on their daily hours.

    As with all timesheets, it has to do calculations with negative times, and therefore it uses the 1904 date system rather than the 1900 date system. This works perfectly everywhere... well, NEARLY everywhere. There is one row which generates a wildly wrong answer. It adds –00:04 to +01:14 and comes up with the crazy answer of –22:50.

    I have attached the timesheet, with personal information removed. I apologise for attaching such a large spreadsheet, but everything is so interlinked, there's no way to cut down the amount of data without changing the data and thus making the problem invisible. The error is on the August worksheet in cell AG11; I have highlighted it in yellow and made it nice and big so it's easy to see.

    Can anyone help figure out what's going on here, and how to fix it? Thanks in advance!
    Attached Files Attached Files

  2. #2
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,829

    Re: Random calculation error with adding and subtracting times

    The calculations look correct to me, so it is either misunderstanding exactly what Excel is doing, or something is incorrectly programmed, and I'm not sure which. Here's what I see happening:

    My first observation is that your time formats are all "time of day" formats ("h:mm"), but you talk about them as if they are "elapsed time" kind of formats ("[h]:mm"). The first thing I did was change the format to an elapsed time format, which shows that what you claim is -4 minutes in AG10 is really -24 hours and 4 minutes -- the time of day format conceals the "day" information that is in the cell value. Of course, -24:04+1:14 (-1.00313+0.0514 -- the actual cell values behind the time formatting) is correctly calculated as -22:50 (-0.95174). I think that, if you will format your cells as elapsed time or even general (where the numbers you see will mean decimal days), you will see that the calculations are correct. Then you will be in a better position to determine if the error is in the formatting or in the actual calculation or if numbers have been entered incorrectly.
    Last edited by MrShorty; 09-02-2020 at 12:01 PM. Reason: left a 0 out of one of the values
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  3. #3
    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: Random calculation error with adding and subtracting times

    Why do you say the answer is crazy?

    It is adding AG10 to AD11
    AG 10 is displayed as a time format -00:04. The underlying number is -1.003
    AD11 displays time format 00:14, underlying number .05138.
    The sum of the two is negative -.95162 which displays as a time format -22:5

    You don't complain that AG9 plus AD10 shows a sum of - 00:04 minutes, why therefore do you complain the about AG10 Plus AD11 showing a total of -.95162, which equates to -22:50 i.e. .95162 * 24 = -22.83888 hours or -22:50.


    What answer do you expect? 1:10 or 1:18. The difference is due to whether the AG + AD calculation is positive or negative. In the earlier rows it was negative. In the AG11 row it is positive. If you want to trap and correct it you will need to include an IF test. Maybe something like

    Formula: copy to clipboard
    Please Login or Register  to view this content.
    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.

  4. #4
    Registered User
    Join Date
    09-02-2020
    Location
    Brussels
    MS-Off Ver
    Office 365
    Posts
    2

    Re: Random calculation error with adding and subtracting times

    Hello both! Thank you so much for your helpful replies, and sorry for the slow acknowledgement -- I have been away and only just come back to this.

    MrShorty, you hit the nail on the head. I had not properly appreciated the difference between the formats hh:mm and [h]:mm, so sometimes Excel was adding times when it should have been adding durations.

    Having fixed this problem, it all works well.

    Thank you again for your invaluable support!

+ 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. [SOLVED] Get rid of error message while subtracting two times
    By chriswrcg in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 06-06-2019, 10:16 AM
  2. [SOLVED] Precision error while adding or subtracting values in excel.
    By alokmpatel in forum Excel General
    Replies: 2
    Last Post: 11-19-2015, 06:38 AM
  3. Adding subtracting times
    By jays35 in forum Excel General
    Replies: 1
    Last Post: 08-23-2012, 10:26 PM
  4. Adding/Subtracting Times
    By controlfreak in forum Excel General
    Replies: 2
    Last Post: 09-09-2009, 04:20 AM
  5. [SOLVED] Adding/Subtracting Dates & Times
    By Kim17740 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 04-11-2006, 08:04 PM
  6. [SOLVED] Rounding Error when adding or subtracting two cells
    By mtheo in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 02-28-2006, 02:55 PM
  7. Subtracting Times
    By bhalchandra2000 in forum Tips and Tutorials
    Replies: 1
    Last Post: 08-23-2005, 12:08 PM

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