So I am trying to convert a string date in the following format to a DateTime. I am able to parse it using ParseExact when there are 7 decimals of fractions of a second usin
I don't believe you can do this with the normal parsing code and the existing text. DateTime's precision only goes down to ticks, where a tick is 100 nanoseconds. I think the simplest thing to do is truncate the string itself:
string pattern = "yyyy-MM-dd HH:mm:ss.fffffff";
if (text.Length > pattern.Length)
{
text = text.Substring(0, pattern.Length);
}
DateTime value = DateTime.ParseExact(text, pattern, CultureInfo.InvariantCulture);
Obligatory plug: in Noda Time 2.0 you won't need to do this as it supports a precision of nanoseconds :)