Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

<SIZE=5>

Hello gurus,

 

I have been lookin at this for like 6 hours now, and I am turnin to you guys...

 

This below is the error I get

 

<B> --- ERROR BEGINS --- </B>

 

String was not recognized as a valid DateTime.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

 

Exception Details: System.FormatException: String was not recognized as a valid DateTime.

 

Source Error:

 

 

Line 248:

Line 249: string myDateTimeValue = "2/16/1992 12:15:12";

Line 250: DateTime myDateTime = DateTime.Parse (myDateTimeValue);

Line 251:

Line 252:

 

 

Source File: c:\inetpub\wwwroot\agentaccountingapp\agent\store_usage.aspx.cs Line: 250

 

Stack Trace:

 

 

[FormatException: String was not recognized as a valid DateTime.]

System.DateTimeParse.GetDayOfNNY(DateTimeResult result, DateTimeRawInfo raw, DateTimeFormatInfo dtfi) +202

System.DateTimeParse.ProcessTerminaltState(Int32 dps, DateTimeResult result, DateTimeRawInfo raw, DateTimeFormatInfo dtfi) +142

System.DateTimeParse.Parse(String s, DateTimeFormatInfo dtfi, DateTimeStyles styles) +488

System.DateTime.Parse(String s, IFormatProvider provider, DateTimeStyles styles) +30

System.DateTime.Parse(String s, IFormatProvider provider) +11

System.DateTime.Parse(String s) +7

AgentAccountingApp.Agent.store_usage.lstBoxWeek_SelectedIndexChanged(Object sender, EventArgs e) in c:\inetpub\wwwroot\agentaccountingapp\agent\store_usage.aspx.cs:250

System.Web.UI.WebControls.ListControl.OnSelectedIndexChanged(EventArgs e) +108

System.Web.UI.WebControls.ListBox.System.Web.UI.IPostBackDataHandler.RaisePostDataChangedEvent() +26

System.Web.UI.Page.RaiseChangedEvents() +115

System.Web.UI.Page.ProcessRequestMain() +1081

 

 

 

 

--------------------------------------------------------------------------------

Version Information: Microsoft .NET Framework Version:1.1.4322.573; ASP.NET Version:1.1.4322.573

 

<B> --- ERROR ENDS --- </B>

 

By the way, that code is strictly taken from msdn site...

There seems to be nothing wrong with the code itself nor import problems...

 

I'm totally lost...HELP!!!

</SIZE>

  • Administrators
Posted

try

            System.IFormatProvider format =
                new System.Globalization.CultureInfo("en-US", true);

            string myDateTimeValue = "2/16/1992 12:15:12";
            DateTime myDateTime = DateTime.Parse (myDateTimeValue,format);

their code is assuming US date / time format. If you are using different regional settings then this will cause your problem.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted

It has something to do with globalization and I think it is expecting a US formatted date because it works fine with

 

string myDateTimeValue = "16/2/1992 12:15:12";

 

try setting the IFormatProvider part of the Parse function.

Posted

Just noticed - of course "2/16/1992" wont work as there are only 12 months in the year. The example is in a US format so just change your string to be UK format and you wont need to add the globalization (unless your from the US).

 

;-)

Posted

Thanks a bunch!!!

 

That fixed it, thanks PlausiblyDamp!!! :D

 

try

            System.IFormatProvider format =
                new System.Globalization.CultureInfo("en-US", true);

            string myDateTimeValue = "2/16/1992 12:15:12";
            DateTime myDateTime = DateTime.Parse (myDateTimeValue,format);

their code is assuming US date / time format. If you are using different regional settings then this will cause your problem.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...