-
January 31st, 2010, 04:33 PM
#1
DateTime.ParseExact - "day of week was incorrect" exception!!
Greetings,
Perhaps this is a bug with DateTime.ParseExact()?
Input:
SUNDAYSEPTEMBER271:00PMET
Code:
prediction.TimeOfGame = DateTime.ParseExact((_date + timeOfGameNoCommasOrSpaces).ToUpper(),
"ddddMMMMdh:mmttET",
null);
Returns:
System.FormatException: String was not recognized as a valid DateTime because the day of week was incorrect.
I'd like to report this, perhaps someone knows the reason for the exception?
Thanks,
Tom
-
January 31st, 2010, 06:35 PM
#2
Re: DateTime.ParseExact - "day of week was incorrect" exception!!
Hi embalism,
You may want to look at the following things...
1. It looks like you haven't specified the year in the format string. I assume the year is 1971 going by the process of elimination. I might be wrong of course. But I think you need to specify the year if you want to create a valid date time.
2. Secondly once you do specify the year, the numbers have to correspond to a real date in the calendar. For example if you want to create 2nd of September 1971 that date was a Thursday and not a Sunday.
3. Thirdly I would probably change the spelling of "SUNDAY" to "Sunday" to match the DaysOfWeek enumeration. The comparison might be case sensitive (I doubt it though...)
-
January 31st, 2010, 06:50 PM
#3
Re: DateTime.ParseExact - "day of week was incorrect" exception!!
Hi,
Ignore point #3. The case doesn't seem to matter. This worked for me...
Code:
var date = DateTime.Format("THURSDAYSeptember02711:00PM", "ddddMMMMddyyh:mmtt", null);
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|