10 Replies Latest reply on Apr 17, 2017 4:38 PM by user25682

Convert Milliseconds to HH:MM:SS.hh

Howdy,

I need to convert a number that represents a big pile of milliseconds from a start time into HH:MM:SS.hh (hh being hundreds of seconds).

Is there a more elegant way of doing it than a bunch of division with If..Then statements?

Thanks!

• 1. Re: Convert Milliseconds to HH:MM:SS.hh

GetAsTime ( Div ( milliseconds ; 10 ) / 100 )

• 2. Re: Convert Milliseconds to HH:MM:SS.hh

Thank you, very much!

• 3. Re: Convert Milliseconds to HH:MM:SS.hh

Why the div function?

can't you just divide by 1000?

• 4. Re: Convert Milliseconds to HH:MM:SS.hh

To get 2 digits in SS.hh (Round() or Ceiling() or field formatting can be used for cases)

• 5. Re: Convert Milliseconds to HH:MM:SS.hh

But for a time value, I don't think that you need to do any rounding or truncating...

• 6. Re: Convert Milliseconds to HH:MM:SS.hh

OP want 2 digits as .hh

GetAsTime(1234567/1000) results 3digits as 0:20:34.567

There was no state for choosing .56 or .57 (round up) so I used Div

• 7. Re: Convert Milliseconds to HH:MM:SS.hh

You can round instead of truncate as you did the div function and you can also just display the value as rounded via data formatting the time value in the inspector. (Round can round a value to values other than just an integer.)

• 8. Re: Convert Milliseconds to HH:MM:SS.hh

"hundredths of seconds", that is.

Is there any way to force this to display the two hundredths digits, even if they're zeros? It will look better on the report. Fixed number of decimals doesn't work. I made it work by extracting the third character from the right and performing concatenations based on that value, but you know, there might be a more elegant way to do that.

Thanks!

• 9. Re: Convert Milliseconds to HH:MM:SS.hh

You'd need text (calculation result) field instead of time.

GetAsTime ( Div ( ms ; 1000 ) ) & SerialIncrement ( ".00" ; Mod ( ms / 10 ; 100 ) )

2 of 2 people found this helpful
• 10. Re: Convert Milliseconds to HH:MM:SS.hh

Perfect.

Thank you, again!