Hi RiteshRaj,
dd/MM/yyyy is not a valid date since dd will be interpreted as the month.
Try using TryParse and specifying the format using ParseExact explicitly.
C#
string date = "31/12/2020";
DateTime dt;
if (!DateTime.TryParse(date, out dt))
{
dt = DateTime.ParseExact(date, "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture);
}
VB.Net
Dim date As String = "31/12/2020"
Dim dt As DateTime
If Not DateTime.TryParse(date, dt) Then
dt = DateTime.ParseExact(date, "dd/MM/yyyy", Globalization.CultureInfo.InvariantCulture)
End If
For Convert.ToDateTime Method refer below link.
Convert.ToDateTime Method