Convert date to another format

I have a string. “29/05/2019”
Converted it to date using Datetime.parseexact(“29/05/2019”,“dd/MM/yyyy”,system.globalization.cultureinfo.invariantculture)

However, it differs on different computer system. if on a system with the datetime format of MM/dd/yyyy, the date becomes 05/29/2019 instead. How do i ensure that the conversion from string to date should always end up in dd/MM/yyyy regardless of the system date format?

Hello @TyraS

Have a look to the below post. It might answer your question and give you exact output.

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:

we can use within parseexact an array with dateFormat strings. So we can parse in one run both formats.

But in case of both formats are not reliable detectable we will get an issue.

29/07/2021 and 05/17/2020 can be parsed and format is clear detectable

05/11/2021 is not clear detectable, as it can be May or November

One strategy could be (if its machine bound)

  • check all dates in advance and check which format is to apply
  • process it with calculated format string

hello, but this gave a string result at the end.

Hello @TyraS

What output did you get?

Can you share the screenshot…!!

Happy Automation :raised_hands:

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

@TyraS

Check below for your reference

Reference

Hope this may help you

Thanks