I want to parse DateTime, here my code:
var datastring =p1.ItemArray[2].ToString();
var format = "dd.MM.yyyy";
var date = DateTime.ParseExact(datastring,format,CultureInfo.InvariantCulture);
p1 – is DataRow, in p1.ItemArray[2] I have value of DateTime
In watch p1.ItemArray[2] have this value : "09/03/2012 00:00:00" his type is DateTime
After parsing throws error: String was not recognized as a valid DateTime.
You could include the time in your format as it seems the string you are trying to parse contains the time:
Also I would recommend you using the TryParseExact method as it provides a better defensive programming pattern instead of throwing exceptions.