Want to add 0 in front of time. My time is stored in string variable

1:00 PM(PDT)
Above is time format stored in string variable and i want to append 0 in start of time like 01:00 PM(PDT).

Trying different things but no use.

Hi @Puneet_Singh

Try this:

Assign
InputTime = “1:00 PM(PDT)”

Assign
FormattedTime = DateTime.ParseExact(InputTime, “h:mm tt’(PDT)'”, CultureInfo.InvariantCulture).ToString(“hh:mm tt’(PDT)'”)

Hope this helps,
Best Regards.

1 Like

I already deleted PDT its not in use and i tried your solution it showing cultureinfo is not declared.

@Puneet_Singh

Since you said you have stored it in a string variable, try concatenation:

“0”+stringVar

Hope this helps,
Best Regards.

3 Likes

@Puneet_Singh

Try this

If(Str.Split({":"},2,StringSplitOptions.None)(0).Length=2,"","0") + Str.Split({":"},2,StringSplitOptions.None)(0) + ":" + Str.Split({":"},2,StringSplitOptions.None)(1)

Cheers

1 Like

You shouldn’t deal with datetimes as strings by doing all this splitting. Convert them to proper datetime then output the format you need.

2 Likes

Hi @Puneet_Singh

Give a try with the following

DateTime.ParseExact(strInput, "h:mm tt'(PDT)'", System.Globalization.CultureInfo.InvariantCulture).ToString("hh:mm tt'(PDT)'")

Regards

1 Like

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