Search code examples
arraysdatetimegoogle-sheetsgoogle-sheets-formulanumber-formatting

Formula to write milliseconds in hh:mm:ss.000 format gives wrong values


I'm trying to convert duration in one column which is written in milliseconds (Ex: 600,2101,1110....) to hh:mm:ss.000 format(Ex:00:00:00.600, 00:00:02.101...) using the below formula in google spreadsheets:

=CONCATENATE(TEXT(INT(A1/1000)/86400,"hh:mm:ss"),".",A1-(INT(A1/1000)*1000))

It gives correct values for almost all , but one type of values which is durations having '0' as their second digit (Eg: 2010,3056,1011). When 0 is the second digit , the after decimal value in hh:mm:ss.000 is rounded to the third digit and 0 is ignored (Example row 1 and 2 in below table). But for other durations it gives right value(row 3). I need a formula that works well on all type of values i.e 1080 → 00:00:01.080 and not 00:00:01.80 . Can someone please help with this.

Duration in milliseconds hh:mm:ss.000 format
1080 00:00:01.80 (wrong)
2010 00:00:02.10 (wrong)
1630 00:00:01.630 (correct)

Solution

  • try:

    =INDEX(IF(A2:A="",,TEXT(A2:A/86400000, "hh:mm:ss.000")))
    

    enter image description here