How can I convert the following strings to a System.DateTime object?
Wednesday 13th January 2010
Thursday 21st January 2010
Wednesday 3rd February 2010
Another alternative using escape characters for handling (st
, nd
, rd
, and th
) without stripping them before the call of DateTime.TryParseExact
string dtstr = "Saturday 23rd January 2016";
DateTime dt;
string[] formats = new string[] {
"ffffdd d\\s\\t MMMM yyyy", "ffffdd d\\n\\d MMMM yyyy",
"ffffdd d\\r\\d MMMM yyyy", "ffffdd d\\t\\h MMMM yyyy" };
bool result = DateTime.TryParseExact(dtstr, formats, CultureInfo.InvariantCulture, DateTimeStyles.None, out dt);