Problem with converting from string to DateTime format

I’m trying to convert string to DateTime format in the way shown below,

but all the tim getting error
“Assign: String was not recognized as a valid DateTime.”
Can you help me with this issue?

Hi @Olivera_Kalinic ,

Can you use “d.M.yyyy” instead of “dd.MM.yyyy”

DateTime.ParseExact(“1.3.2022”,“d.M.yyyy”,System.Globalization.CultureInfo.InvariantCulture)

Note: If your input will be 01.03.2022. You can use “dd.MM.yyyy”

Thanks!

Hi @Olivera_Kalinic

How about this Date expression?

DateTime.ParseExact("1.3.2022",{"d.M.yyyy","dd.MM.yyyy","M.d.yyyy","MM.dd.yyyy"}, System.Globalization.CultureInfo.InvariantCulture,System.Globalization.DateTimeStyles.None)

image

Regards
Gokul

@Gokul001

I have to get date in format “dd.MM.yyyy”, not in “MM/dd/yyyy hh:mm:si”

HI @Olivera_Kalinic

Try with this expression

DateTime.ParseExact("1.3.2022",{"d.M.yyyy","dd.MM.yyyy","M.d.yyyy","MM.dd.yyyy"}, System.Globalization.CultureInfo.InvariantCulture,System.Globalization.DateTimeStyles.None).ToString("dd.MM.yyyy")

Regards
Gokul

image