This occurs due to the invalid value of the date time format expected. For example, I have the code below in vb.net.
Dim dateT As DateTime
Thread.CurrentThread.CurrentUICulture = New CultureInfo("en-US")
Thread.CurrentThread.CurrentUICulture = New CultureInfo("de-DE")
If Not IsNothing(txtDate.Text) Then
dateT = Convert.ToDateTime(txtDate.Text)
Else
dateT = DateTime.Today
End If
MessageBox.Show(String.Format("The current cultrue is : {0} and entered date time is: {1} ", Thread.CurrentThread.CurrentUICulture.ToString(), dateT.ToString()))
This code will be working fine for the value:
8/26/2013 10:0:37 AM
This follows mm/dd/yyyy format.
But, it will throw an error if the value becomes:
26/8/2013 10:0:37 AM
This follows dd/mm/yyyy format.
So, Please check the current culture and pass the value accordingly.