"Conversion from string "16-11-2023" to type 'Date' is not valid. " why this Error is coming

Why is this Exception throwing in some date?
Please help me to solve this.

@Ajinya_jorwekar

DateTime.ParseExact(str_InputDate,"dd-MM-yyyy",system.Globalization.CultureInfo.InvariantCulture).ToString("MM.dd.yyyy")

grafik

Hi @Ajinya_jorwekar

Try giving this:

Str_InputDate="16-11-2023"
Output= DateTime.ParseExact(Str_InputDate,"dd-MM-yyyy",System.Globalization.CultureInfo.InvariantCulture).ToString("MM.dd.yyyy")

Hope it helps!!

Hi,

FYI, if your input may has single digit month or day (this means 28-2-2023 for example), the following expression is better. (This can handle 1 and 2 digit month and day)

DateTime.ParseExact(Str_InputDate,"d-M-yyyy",System.Globalization.CultureInfo.InvariantCulture).ToString("MM.dd.yyyy")

Regards,

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