Extracting date in particular format

Hi,

I am trying to extract a date from a string. The string will either be like this: “19/05/2021”. or may have extra characters or spaces like this: "@’ 23/06/2021 ".

I am able to get the date in the format it want(yyyy-MM-dd) for the first example using the below code

DateTime.ParseExact(MyString, “dd/MM/yyyy”,System.Globalization.CultureInfo.InvariantCulture).ToString(“yyyy-MM-dd”)

However i get this error for the second example: “String was not recognized as a valid DateTime”

Any ideas?

if this string is send to parseExcact, sure it is not recognized.

Maybe cleansing with regex can help

2 Likes

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