I'm getting this error, while trying to parse a DateTime
string:
String was not recognized as a valid DateTime.
var input = "25-JUL-19 03.22.05.036000000 PM"
var output = DateTime.ParseExact(input, "dd-MMM-yy hh.mm.ss.fffffff tt",
CultureInfo.InvariantCulture, DateTimeStyles.None);
I tried it with 9 f
in the format string, which leads to the same error.
Update
I find out two ways to get this to work:
Method 1:
System.Globalization.CultureInfo provider = System.Globalization.CultureInfo.InvariantCulture;
format = String.Format("dd-MMM-yy hh.mm.ss.fffffff{0} tt",
input.Substring(26, 2)); // substring to handle .Net's lower precision
output = DateTime.ParseExact(input, format, provider);
Method 2:
output = (DateTime)((OracleTimeStamp)inputParam.Value);
where "inputParam" is declared as:
var inputParam = new OracleParameter("SOME_TIMESTAMP", OracleDbType.TimeStamp, null, ParameterDirection.Output);