How can I turn "1 hr 14 min 15 sec" string format into a Double format?

Hey guys! Hopefully, you can help me with this :slight_smile:

I’m currently extracting data from a table that gives me time format in a string format

image

I need to turn these values into a Double, converting the value into minutes. So, for example, the string “1 hr 5 mins” needs to be shown as 65.0. The String “9 mins 24 secs” needs to be shown as 9.4.

I’ve already extracted the data, have it in a datatable, and can access each cell but I’m unsure of how I can split the string up to do the math. Any help would be greatly appreciated! :smile:

1 Like

how about u write a code on some IDE and change hours to minutes? the start that process in uipath that processes the time conversion

Hi
The expression be like this inside the for each row loop
row(“yourcolumnname”) = IF(row(“yourcolumnname”).ToString.Contains(“hr”) AND row(“yourcolumnname”).ToString.Contains(“mins”),
Cint(System.Text.RegularExpressions.Regex.Match(row(“yourcolumnname”).ToString,”.\d\s(?=hr)”).ToString.Trim)*60+Cint(System.Text.RegularExpressions.Regex.Match(row(“yourcolumnname”).ToString,”.\d\s(?=min)”).ToString.Trim),
IF(row(“yourcolumnname”).ToString.Contains(“mins”) AND row(“yourcolumnname”).ToString.Contains(“sec”),
Cint(System.Text.RegularExpressions.Regex.Match(row(“yourcolumnname”).ToString,”.\d\s(?=min)”).ToString.Trim)+Cint(System.Text.RegularExpressions.Regex.Match(row(“yourcolumnname”).ToString,”.\d\s(?=sec)”).ToString.Trim),
IF(row(“yourcolumnname”).ToString.Contains(“mins” ), Cint(System.Text.RegularExpressions.Regex.Match(row(“yourcolumnname”).ToString,”.\d\s(?=min)”).ToString.Trim), Cint(System.Text.RegularExpressions.Regex.Match(row(“yourcolumnname”).ToString,”.\d\s(?=sec)”).ToString.Trim)))

Cheers @Btrumps

2 Likes

I think your best bet is to use regex expressions, but im afraid im not very good with them, after that you can use TimeSpan class to retrieve it in minutes.

Awesome, thanks @Palaniyappan!

1 Like

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