+ Reply to Thread
Results 1 to 8 of 8

Convert negative time to negative decimal

  1. #1
    Registered User
    Join Date
    01-05-2015
    Location
    England
    MS-Off Ver
    2010
    Posts
    4

    Convert negative time to negative decimal

    Hi All,

    I have a spreadsheet supplied that has a column with both positive time values and negative time values (ie 146:30 & -7:30 etc). There could be over 1000 rows. I need to be able to sum all the positive times and seperatly sum all the negative times and display both in decimal. I was intending to use SIGN() to seperate the positive and negative but can't get it to work with negative Time values, it just gives #VALUE error. Next thought was to convert the Time to decimal. No problem with the positive (142:30 *24 etc) but need a way to convert the negative time to a negative decimal so -7:30 becomes -7.50. For the life of me i cannot get the result with the negative. Again I just get #VALUE error as -7:30 * 24 does not work.


    Anyone have any ideas????

  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: Convert negative time to negative decimal

    You need to use the 1904 date system to display negative times:

    A
    B
    C
    D
    1
    Time
    2
    -135:40
    Sum Pos
    26.47
    C2: =SUMIF($A$2:$A$22, ">0")
    3
    131:05
    Sum Neg
    -38.29
    C3: =SUMIF($A$2:$A$22, "<0")
    4
    106:16
    5
    9:32
    6
    -140:59
    7
    -134:01
    8
    -53:15
    9
    -46:10
    10
    -8:45
    11
    -107:40
    12
    -63:45
    13
    43:31
    14
    55:07
    15
    -1:12
    16
    -48:39
    17
    -141:27
    18
    -37:23
    19
    91:40
    20
    78:19
    21
    61:56
    22
    57:43
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Forum Expert
    Join Date
    05-01-2014
    Location
    California, US
    MS-Off Ver
    Excel 2010
    Posts
    1,795

    Re: Convert negative time to negative decimal

    Since Excel does not normally support negative time [1], I presume that what appears to be "-7:30" is actually text, not numeric. That would explain why "-7:30"*24 results in a #VALUE error.

    The following should work:

    =TEXT(SUMPRODUCT( (LEFT(A1:A4,1)="-")*(--MID(A1:A4,2,99)) ), "\-[h]:mm")

    Caveat: I assume that 7:30 is 7 hours 30 minutes, not 7 minutes 30 seconds.

    PS.... To display as a decimal number:

    =-SUMPRODUCT( (LEFT(A1:A4,1)="-")*(--MID(A1:A4,2,99)) ) * 24


    -----
    [1] Unless you select the 1904 date system, which I do not recommend unless you have a Mac file.
    Last edited by joeu2004; 08-22-2018 at 11:46 AM.

  4. #4
    Registered User
    Join Date
    01-05-2015
    Location
    England
    MS-Off Ver
    2010
    Posts
    4

    Re: Convert negative time to negative decimal

    Hi, thanks for the replies.

    1, Negative times display correctly on the spreadsheet (-7:30, yes it is 7 hours 30 mins).
    2, I have been using 1904 date with no success.

    In the attached, column A is a sample of the data received (could be well in excess of 1000 rows)
    Column B is the result of running SIGN() on the value
    Column C is the result of trying to convert to a decimal
    Column D is my manual entry of what i need the data to be (D4 should be 7.25 not 7.50 :-))
    Column E is the new result of running SIGN() on what the data should be
    And the results are just that, the results/
    Attached Files Attached Files
    Last edited by Ogrid; 08-22-2018 at 12:10 PM.

  5. #5
    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: Convert negative time to negative decimal

    Your workbook wasn't set to use the 1904 date system, and all your times are text. With default horizontal alignment, numbers always align right (unless formatted as Text). Negative time values need to be entered as, for example, -"7:15"

    A
    B
    C
    D
    1
    Time Balances
    Result
    2
    0:00
    3
    60:00
    Total Minus
    -29.10
    C3: =SUMIF(A2:A16, "<0") * 24
    4
    -7:15
    Total Plus
    420.60
    C4: =SUMIF(A3:A17, ">0") * 24
    5
    142:30
    6
    11:45
    7
    0:00
    8
    0:00
    9
    93:00
    10
    30:51
    11
    0:00
    12
    82:30
    13
    -21:51
    14
    0:00
    15
    0:00
    16
    0:00
    Last edited by shg; 08-22-2018 at 12:29 PM.

  6. #6
    Forum Expert
    Join Date
    05-01-2014
    Location
    California, US
    MS-Off Ver
    Excel 2010
    Posts
    1,795

    Re: Convert negative time to negative decimal

    Re: test sheet.xls

    Enter the following into C2 and copy down:

    =IF(ISNUMBER(--A2), A2, -MID(A2,2,99))*24

    Enter the following SUMIF formulas:

    H3: =SUMIF(C2:C16,"<0")
    H4: =SUMIF(C2:C16,">0")

    Or if you want to avoid the "helper" cells in column C, array-enter the following (press ctrl+shift+Enter instead of just Enter):

    H3: =SUM(IF(ISNUMBER(--A2:A16)=FALSE, -MID(A2:A16,2,99)))*24
    H4: =SUM(IF(ISNUMBER(--A2:A16), A2:A16*24))

    By the way, your expectations in column D are wrong in some cases. -7:15 is -7.25, not -7.50. -21:51 is -21.85, not -21.80. Of course, that causes differences in H3, as well.


    -----
    FYI, one reason to avoid setting the 1904 Date System option: you will encounter problems when copying bona fide dates (not the text that you have) between workbooks that do not have the 1904 Date System set (most common).


    -----
    [EDIT] You could also array-enter the following equivalent formulas into H3, whatever you prefer:

    =SUM(IF(ISNUMBER(--A2:A16), FALSE, -MID(A2:A16,2,99)))*24
    or
    =SUM(IF(NOT(ISNUMBER(--A2:A16)), -MID(A2:A16,2,99)))*24
    Last edited by joeu2004; 08-22-2018 at 02:14 PM.

  7. #7
    Registered User
    Join Date
    01-05-2015
    Location
    England
    MS-Off Ver
    2010
    Posts
    4

    Re: Convert negative time to negative decimal

    Thank joeu2004,

    That works perfectly. I knew about the typos in converting time to decimal, just did it quickly so i could post the sheet. I deal with time - decimal every day with my job.

    Regards

  8. #8
    Forum Expert
    Join Date
    05-01-2014
    Location
    California, US
    MS-Off Ver
    Excel 2010
    Posts
    1,795

    Re: Convert negative time to negative decimal

    Quote Originally Posted by joeu2004 View Post
    FYI, one reason to avoid setting the 1904 Date System option: you will encounter problems when copying bona fide dates (not the text that you have) between workbooks that do not have the 1904 Date System set (most common).
    You're welcome! One clarification: in my caveat above, I should have emphasized dates per se.

    There is no problem with times alone because the "date" is zero.

    But if you have any dates or you might add them later, it will cause "mysterious" problems when copying them. Just a bad idea, IMHO.

+ 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. Need a formula to change a negative time to negative decimal
    By Renejorgensen in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 12-12-2016, 11:51 AM
  2. Replies: 9
    Last Post: 04-20-2016, 02:42 AM
  3. Decimal power of a negative value
    By hinubhai in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-06-2014, 01:27 PM
  4. decimal powers of negative numbers
    By samartil in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 05-04-2013, 12:57 AM
  5. Correcting negative decimal hours
    By BigAl_Qld in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-30-2012, 10:45 AM
  6. Non-decimal arithmetic: old £ s d and a negative balance
    By jd_jd in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 07-19-2011, 01:51 PM
  7. Convert negative to positive in sheet containing both positive/negative numbers
    By sa02000 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-29-2010, 07:52 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