Time to datatime

hi all
I have this text for example: “0:1:30:12”
-the first number indicates the number of days
-the second the number of hours
-the third the number of minutes
-the last number of seconds
the idea is to convert 00:01:30:12
that all remain with that format (dd / hh: mm: ss)

help!

Fine
hope this expression would help you resolve this
if the input is a string
str_input = “0:1:30:12”
then
in assign activity

str_output = If(Split(str_input,“:”)(0).Length.Equals(1),“0”+Split(str_input,“:”)(0),Split(str_input,“:”)(0))+“:”+If(Split(str_input,“:”)(1).Length.Equals(1),“0”+Split(str_input,“:”)(1),Split(str_input,“:”)(1))+“:”+Split(str_input,“:”)(2)+“:”+Split(str_input,“:”)(3)

where this str_output can be parsed as timespan like this
TimeSpan.Parse(str_output)

cheers @fernando_zuluaga

1 Like

hi @Palaniyappan

it works, thanks you!

regards,

1 Like

But that looks like a lot of mess, your string can be parsed as TimeSpan so will look a lot better like this:

myTimeSpanVariable = TimeSpan.Parse(“0:1:30:12”)
myFormattedText = myTimeSpanVariable.Days.ToString + " / " + myTimeSpanVariable.Hours.ToString + ": " + myTimeSpanVariable.Minutes.ToString + ": " + myTimeSpanVariable.Seconds.ToString

1 Like

i wanted, the output takes this format (“dd/hh:mm:ss”) and your code returns that: (“d/h:mm:ss”), i mean, format in two numbers ever ("00:00:00:00)

thanks!

ok, just put ToString(“00”) instead and it will give two digits format :wink:

1 Like

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