Is it possible to convert these lines at the right time? "Friday August 31, 2012"; "26-Jul-2012" "190811"
Yes, since you parse dates in specific formats, you should use DateTime.TryParseExact . DateTime.TryParse will internally call DateTime.Parse , which will try to parse dates only using some predefined formats. From the docs:
The DateTime.Parse (String) method attempts to convert a string representation of a date and time into its DateTime equivalent. The string to be parsed can take any of the following forms:
A string with a date and time component.
A string with a date but no time component.
A string with time, but not with a date component.
A string that includes time zone information that complies with ISO 8601. For example, the first of the following two lines indicates Coordinated Universal Time (UTC); the second indicates the time in the time zone seven hours earlier than UTC:
2008-11-01T19:35:00.0000000Z
2008-11-01T19:35:00.0000000-07:00
A string that includes the GMT symbol and corresponds to the temporary format RFC 1123. For example:
Sat, 01 Nov 2008 19:35:00 GMT
A string that includes the date and time, as well as information about the time zone offset. For instance:
03/01/2009 05:42:00 -5:00
It is important to note that when you do not provide these methods with any culture information obtained from the current stream, which, if you have not explicitly indicated it, tends to be like your car. Therefore, if the dates you are trying to analyze have a certain culture, they will be more likely than not to understand normally, for example. both "Friday 31 August 2012" / "26-Jul-2012" analyze using TryParse for me, since my default culture is en-GB, however "190811" fails (I would assume that for all cultures), as it is not a system recognized date format. Therefore, TryParseExact more reliable.
James source share