How to change the hh:mm:ss format in spreadsheets

0

Currently, I have a data set which is "mm:ss" and needs to stay / be calculated that way.

The problem is, Microsoft Excel, Google Spreadsheets and OpenCalc all interpret "mm:ss" as "hh:mm" and to add insult to injury add ":ss" (in form of ":00") to anything I copy into Excel/GSheets/Calc.

  1. I have found no way to remove this, except to use "Search and Replace" first ":" then "00" and then at last apply the custom format 0:00:00 or 0":"00":"00. (I also tried to get "=Concatenate" to work, but that didn't work for me at all...)

  2. Additionally, using the "0:00:00" is in fact only working if I already have a spreadsheet. When I copy the original data (from MS OneNote) into a cell formatted with 0:00:00, I don't have the problems described, but the copied data still contains ":", as MS OneNote doesn't have a "Search and Replace" function. My only idea is to take an extra step and copy the data to Notepad and back.

But both approaches are no solution, because my next step should be to sum up those numbers.

Which doesn't work, because any base numbers look like "1234" and not "12:34" (twelve minutes thirty-four seconds, i.e. I am not talking about 12:34 AM/PM (time) but duration!) as they should.

As far as I understood, to sum up minutes properly, I have to use the custom format "[h]:mm:ss", but the problem is that I first have to get the data to (basically) "0:mm:ss" from currently "hh:mm:00". But it is important to remember that those aren't in fact hours! (i.e. /60 doesn't work, because it produces wrong numbers!) The "hh" in question are actually "mm", but because Excel/Calc/GSheets forces their data-interpretation on me without any way of recource of changing this setting, I am out of options.

I never used VBA before, but I am willing to try it.

grunwald2.0

Posted 2013-03-10T05:48:58.340

Reputation: 734

I want to add that I googled around quite a lot, but all solutions that I found were related to simply summing up hh:mm data, which is much easier, if the data base is already (in) hours - inlike mine. – grunwald2.0 – 2013-03-11T14:47:49.140

Answers

1

I've written a VBA function that will add your minutes and seconds:

Function addTime(rng As Range) As String
    Dim timeArray As Variant
    Dim sumSec As Integer
    Dim sumMin As Integer
    Dim i As Range

    Dim secStr As String
    Dim minStr As String
    Dim hrStr As String

    sumMin = 0
    sumSec = 0

For Each i In rng
        On Error GoTo Continue
        If i.Value <> "" Then
            timeArray = Split(i.Value, ":")
            sumMin = sumMin + timeArray(0)
            sumSec = sumSec + timeArray(1)
        End If
Continue:
        On Error GoTo 0
    Next i

    secStr = Modulo(sumSec, 60)
    If (secStr < 10) Then
        secStr = "0" & secStr
    End If

    minStr = Modulo((sumMin + sumSec \ 60), 60)
    If (minStr < 10) Then
        minStr = "0" & minStr
    End If

    hrStr = sumMin \ 60

    addTime = hrStr & ":" & minStr & ":" & secStr    
End Function

Function Modulo(a, b)
    Modulo = a - (b * (a \ b))
End Function

Put the two functions in a module.

To use my function, first you need to get your data into Excel as-is, i.e. not let Excel change the data into its date-time format. So:

  1. First, click the column(s) you want to paste your data in
  2. Convert the Format to "Text"
  3. Paste your data
  4. Type =addTime(A1:A10) (using "A1:A10" as an example of 10 data points)

Amer

Posted 2013-03-10T05:48:58.340

Reputation: 1 189

Thanks Amer, I'll try this out ASAP! Sadly I have already irreversibly converted my data from OneNote to Excel at the moment. But I'll it out with a new dataset. – grunwald2.0 – 2013-03-11T14:46:26.347

0

If I understand correctly, then your problem is

1) how to enter hh:ss data without Excel messing it up

2) how to sum them and get the right answer

I know this is a hack, but if you use format [h]:mm, then enter your data, it will work.

Even though you enter minutes and seconds, Excel it will do the math as if it is hours and minutes, but numerically it will give you the answer you want, e.g. 1:45 + 1:30 = 3:15 and 51:45 + 61:30 = 113:15

gabriel

Posted 2013-03-10T05:48:58.340

Reputation: 101

hh:ss isn't possible as far as I know. Only hh:mm or mm:ss. What do you mean thus? – grunwald2.0 – 2013-03-10T08:04:27.447

And I used [h]:mm, but the problem is it won't work properly, because the data base is false! If excel calculates hh:mm, while the actual numbers represent mm:ss, I will get a wrong solution. – grunwald2.0 – 2013-03-10T08:13:02.937

grunwald2 ... This is confusing. You start by saying "The problem is, Microsoft Excel, Google Spreadsheets and OpenCalc all interpret "mm:ss" as "hh:mm" ", then I show with examples that the math works the same for hh:mm as mm:ss. Next you make a statement "I will get a wrong solution". Can you elaborate and give an example please? – gabriel – 2013-03-10T18:19:57.507

Well, I actually just noticed IT WORKS correctly after I put the measures in place I described above. But not entirely, because the break-off point seems to be "100" not 60, to when a value is moved to the left. i.e. with a short array of numbers it somehow works, but if they get more, the calculation is off, because both minutes and seconds get /100 not /60 by the SUM function. – grunwald2.0 – 2013-03-11T02:40:59.937

The problem why your solution doesn't work, that in my case I don't enter the data, MS OneNote does !! So it is automatic, it is already there, i.e. I cannot "prep" the Custom format! -.- And again, I don't want to have to retype all my data, then why do I need excel? Then I'm faster with pen & paper or my manual calculator!! – grunwald2.0 – 2013-03-11T02:42:49.077

0

If you import mm:ss data but excel treats it as hh:mm then you can divide by 60 to convert to the correct mm:ss data.

To divide a whole range of time values by 60 you can use this method:

  1. Put 60 in an empty cell and copy that cell
  2. Select your range of hh:mm values
  3. Right-click and choose "Paste Special" from the menu
  4. In the next dialog box under "Operation" choose "Divide" > OK > ESC
  5. Re-format in the required mm:ss format

Now your values will look the same as before but excel is now treating them as mm:ss as required

This link shows a worksheet with random time values in column A (formatted as [h]:mm) and then columns B & C has the column A value divided by 60 but formatted two different ways - notice how column A looks identical to column C - press F9 to generate different time values

barry houdini

Posted 2013-03-10T05:48:58.340

Reputation: 10 434

Nope, Excel doesn't convert 90:15 to 1:30:15, so how is dividing by 60 gonna help? I tried to describe several times that dividing doesn't help. If I e.g. have the value 30:30(:00) (minutes:ss) and divide it by 60, then the new value is - yes - in minutes 00:50:50, which is more than the original value, i.e. totally wrong. – grunwald2.0 – 2013-03-11T02:36:26.540

@grunwald2.0 -- Have you tested it? I wrote 90:15 into OneNote, copied it into Excel, where it converted to 90:15:00 (hh:mm:ss). Divided by 60 it returned 1:30:15 (hh:mm:ss) or 90:15 formatted with [mm]:ss. Also, I've never, ever seen barry post anything wrong when it comes to time/date issues. – teylyn – 2013-03-11T07:53:27.267

1Thanks teylyn - I know it works but I tested it before I posted anyway - it certainly worked for me - how do you get 30:30 converted to 00:50:50? If you divide 30 hours by 60 you get half an hour which is 30 minutes, if you divide 30 minutes by 60 you get 30 seconds, so 30:30:00 divided by 60 gives you 00:30:30 as required - what am I missing? – barry houdini – 2013-03-11T10:49:02.530

1OK, thinking about it I can see that if you have converted a time value 30:30 to a number 3030 then dividing by 60 will give you 50.5 which doesn't help.......the division by 60 has to be applied to the original time values not the "pseudo" time values formatted as 0:00:00 – barry houdini – 2013-03-11T11:30:15.363

1I added a link to my answer - it shows random time values divided by 60 - you can see that any xx:yy hours:mins value is converted to an identical looking xx:yy mins/secs value – barry houdini – 2013-03-11T11:49:22.033

Again, sadly I have little influence on the mess MS OneNote and Excel produce together, I can only try to wrap my head around of how to manipulate the existing data such as 12:20:00 (hh:mm) towards what I need. Alternatively, I have the "pure" data in OneNote, but the problem is, any spreadsheet software I tried converts my data to hh:mm(:ss) without me having a say concerning this upon import. Am I missing an import option somewhere? – grunwald2.0 – 2013-03-11T14:38:47.867

Ok, sorry, @barryhoudini it seems to indeed work to also take a sum of those. But I have frankly problems to understand how these random numbers relate to my data? i.e. how do I manipulate my "A" column data row to work equivalent to the file you attached? Again, my times aren't initially in the [h]:mm format, but in the default custom excel format, in my case that was hh:mm, no idea why. My target format is: mm:ss or [h]:mm:ss – grunwald2.0 – 2013-03-11T14:53:47.667

They were just examples to show you how the division by 60 would work to convert any hh:mm to mm:ss - I would still suggest that you use the approach I proposed in my answer to convert a whole range of hh:mm data to mm:ss....or you can use a formula in an adjacent column as per my example worksheet – barry houdini – 2013-03-11T15:00:23.527