I have some client code that sends date in the following format "1/31/2013 11:34:28 AM";
I am trying to cast it into DateTime object
string dateRequest = "1/31/2013 11:34:28 AM";
DateTime dateTime = DateTime.Parse(dateRequest);
this throws
String was not recognized as a valid DateTime.
how can i cast it?
You will have to use the
DateTime.Parse(String, IFormatProvider)overload and specify culture-specific information ( or InvariantCulture).You can also create a specific culture with something like:
Or use
DateTime.ParseExactand specify the format string.