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
@J_Swali
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”.
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.
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! Thanks for the amazing help.