Sudeep wrote:
I need to parse following string.
string dt = "Thur 11/2/2006 9:05:52 PM";
DateTime.Parse() or TryParse() fail to parse the given string. The day
in the above string "Thur" is causing the problem . If i change this
to "Thu" it gets parsed. Is there any way i can parse this string
without having to manually change "Thur" to "Thu".
Fix whatever is generating that non-standard format.
If that is not possible then:
string s = "Thur 11/02/2006 9:05:52 PM";
CultureInfo ci = (CultureInfo)CultureInfo.CurrentCulture.Clone();
DateTimeFormatInfo dtf = (DateTimeFormatInfo)ci.DateTimeFormat.Clone();
dtf.AbbreviatedDayNames = new string[] { "Sund", "Mond", "Tues", "Wedn",
"Thur", "Frid", "Satu" };
dtf.DateSeparator = "/";
dtf.TimeSeparator = ":";
dtf.AMDesignator = "AM";
dtf.PMDesignator = "PM";
ci.DateTimeFormat = dtf;
DateTime dt = DateTime.ParseExact(s, "ddd M/d/yyyy h:mm:ss tt", ci);
Arne