ParseExact method will allow you to specify the exact format of your date string to use for parsing. It is good to use this if your string is always in the same format.
string iString = "2005-05-05 22:12 PM";
DateTime oDate = DateTime.ParseExact(iString, "yyyy-MM-dd HH:mm tt", System.Globalization.CultureInfo.InvariantCulture) ;
The CultureInfo.InvariantCulture property is neither a neutral nor a specific culture. It is a third type of culture that is culture-insensitive. It is associated with the English language but not with a country or region.
Full Source:..C# String To DateTime
Originally Posted by SimoNWellborne
I am trying to convert a string representation of a date in the format of yyyymmdd to a DateTime.
I'm trying to use inbuilt methods rather than write something custom.
Am I missing something very easy here (quite possible)?
Appreciate any replies.