User351619809 posted
am passing a valid datetime in string format from my front end aspx page to back end aspx.cs file. When I pass the date time string, I get an exception saying string was not recognized as a valid date time. Below is my code:
if (DOB != "")
{
DateTime formatDate = DateTime.ParseExact(DOB, "MM-dd-yyyy", System.Globalization.CultureInfo.InvariantCulture);
DOB = formatDate.ToString("yyyy-MM-dd");
}
when I am passing the date time, my culture is set to:
Thread.CurrentThread.CurrentCulture = new CultureInfo("es-MX");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("es-MX");
when I set the cultureInfo to "en-US" then I don't get the "string was not recognized as a valid date time" error, but as soon as I set the culture Info to "es-MX", I get this error.
Below is the screen shot of the date that I am passing to above code:

and this is the screen shot of the error that I am getting:

Instead of DateTime.ParseExact, I also tried DateTime.Convert and that is also throwing the same error.
Any help or hint will be greatly appreciated.