DateTime.ParseExact - "day of week was incorrect" exception!!
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: DateTime.ParseExact - "day of week was incorrect" exception!!

  1. #1
    Join Date
    Jan 2010
    Posts
    1

    Exclamation 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

  2. #2
    Join Date
    Nov 2002
    Location
    .NET 3.5 VS2008
    Posts
    1,039

    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...)

  3. #3
    Join Date
    Nov 2002
    Location
    .NET 3.5 VS2008
    Posts
    1,039

    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
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center