Match date data format

If the date format of the input data is very different, is there a way to fit it into one format?
for example :
Case 1: yyyyMMdd
Case 2: yyyyMMddhhmmss
Case 3: yy-MM-dd
Case 4:yyMMdd
Case 5: yy.MM.dd
etc. are very diverse.
Is there a way to change it to one format (yyyy-MM-dd)?

Hi @bbbb

Try the below syntax:

DateTime.ParseExact(yourvariable, {"yyyyMMdd", "yyyyMMddhhmmss", "yy-MM-dd", "yyMMdd", "yy.MM.dd"}, System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None).ToString("yyyy-MM-dd")

Regards

Thank you for answer.
However, I don’t know what cases will come in other than the format I wrote down.

So do I have to add it every time a case is discovered?

Yes, @bbbb. You have to add every time a case is discovered or try maintaining a single format so that you need not change the syntax.

Regards