sforsandeep sforsandeep - 2 months ago 13
Vb.net Question

Date Parse triggers error in ASP.NET

I'm trying to parse a date string in 'mm/dd/yyyy' to date type. But it triggers an error saying

String was not recognized as a valid DateTime.

This is the code Im using

Dim mydate As Date
If filter = 4 Then
mydate = Date.ParseExact(datepart, "mm/dd/yy", System.Globalization.DateTimeFormatInfo.InvariantInfo)
End If

I didnt understand what I did wrong.

This is the datepart value when the error tirggered



Your date format is wrong, use MM/dd/yyyy instead mm/dd/yy try below

Date.ParseExact(datepart, "MM/dd/yyyy", CultureInfo.InvariantCulture)