Formating string

Hi UiPath,

How can we transform a string to a specific format?

let say I do have the following string “20211006”

and I want it to be “2021.10.06” ?

Can someone help me?

thanks in advance

AA

1 Like

@aapostol

Check below for your reference

Reference

Hope this may help you

Thanks

1 Like

Hello @aapostol

May I know that is the string data is date or just a random string?

If yes then below expression might work for you:-

DateTime.ParseExact(“20211006”, “yyyyMMdd”, System.Globalization.CultureInfo.InvariantCulture).ToString(“yyyy.MM.dd”)

Mark as a solution and like it if this helps you :slight_smile:

Happy Automation :raised_hands:

Best Regards
Er Pratik Wavhal :robot::man_technologist:t4: :computer:

Hi

Let me give two expression in this case reason being 10 can be month 06 can be a date possibly
Or
10 can be date and 06 can be month at times

If you know the format exactly then use the corresponding one

For first case

Datetime.ParseExact(invariable.ToString,”yyyyMMdd”,System.Globalization.CultureInfo.InvariantCulture).ToString(“yyyy.MM.dd”)

For second case same but with different format

Datetime.ParseExact(invariable.ToString,”yyyyddMM”,System.Globalization.CultureInfo.InvariantCulture).ToString(“yyyy.MM.dd”)

Hope this would help you resolve this

Cheers @aapostol

1 Like

Hi @aapostol
Try this expression

DateTime.ParseExact(“20211006”, “yyyyMMdd”, System.Globalization.CultureInfo.InvariantCulture).ToString(“yyyy.MM.dd”)

Regards
Sudharsan

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