Convert string of seconds into h : m : s format


I would like to know how to convert a string of seconds “241” and convert it into the following i.e 12h 05m 01s | Bare in mind I am trying to convert a string which is being extracted from a for each task for a databtable. As the value in my datatable is a column called “Business elapsed time” which is seconds.

If i convert this to an integer the BOT does not like this and returns the value 0

1 Like

You can convert your string to a TimeSpan by doing TimeSpan.FromSeconds(Integer.Parse(timeString)). Create a variable with type System.TimeSpan and use an Assign to save the value as a TimeSpan.

Then to format it you can use the Hours, Minutes, and Seconds properties of the TimeSpan class. For your example of “241” you can do timeSpanVar.Hours.ToString + "h " + timeSpanVar.Minutes.ToString + "m " + timeSpanVar.Seconds.ToString + "s" which will output as “0h 4m 1s”.


Kindly have a view on this thread

Cheers @J_Swali

This is the correct approach, but from there you can use ToString to output it in a certain format.
Check out the official documentation for timespan ToString for all the specific bits you can extract.

You’d need something like yourTimespan.ToString(“hh\h\ mm\m\ ss\s”)
h for hours, m for minutes, s for seconds, and any character you want to display has to have a \ before it - so the \h\ prints h then a space.

1 Like

This is not working :frowning:

I am getting these errors. Im trying to assign my row to a string but whenever I log message that string it does not return me a value or the same value as row(“Columnheader”)

Thank you for providing this solution. It seemed like it didnt like it when I was assigning my row to a string so i did the following : TimeSpan.FromSeconds(Integer.Parse(row(“ColumnHeaderName”).ToString))

then did the rest from there! :slight_smile: Thanks for the amazing help.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.