Date Error when adding an Event

Topics: Developer Forum, User Forum
Mar 11, 2011 at 1:11 PM


I download version 1.3.1 to use for a new website. I have the language set to English (United States). I created a page with the news list and events sections. I can add an entry to the news list with no problems. When I try to add an entry to the events I receive the "string was not recognized as a valid DateTime" error below. I have a website with version 1.2 that has no problems with events.

I thought maybe there was an issue with 1.3.1, since it was just released, so I tried replaceing both the EventList.ascx and EventList.ascx.cs files in section controls folder with the ones from version 1.3.0, but no change to the problem. I also deleted the page and tried it again, but I still get the error. I also get it when running it locally via Visual Studio. I just do not know C# or how to troubleshoot it in Visual Studio with breakpoints and such.

For the error below the Event Date was set to March 25, 2011 and it displays as 25-03-2011. The Show From date was set to March 11, 2011 and it displays as 11-03-2011. I had thought setting language to English (United States) also controlled the date format, but maybe not.

What have I done wrong that is causing this error? Is it a bug? Has anyone else experienced it? Any help is greatly appreciated.




Server Error in '/' Application.

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 140:            row["EventLocation"] = txtEventLocation.Text.Trim();
Line 141:            row["EventText"] = txtEventDescriptionHtml.Text.Trim();
Line 142:			row["EventDate"] = DateTime.Parse(txtEventDate.Text).AddHours(Convert.ToInt32(txtEventHours.SelectedValue)).AddMinutes(Convert.ToInt32(txtEventMinutes.SelectedValue)); //dteEventDate.DateValue.AddHours(Convert.ToInt32(txtEventHours.SelectedValue)).AddMinutes(Convert.ToInt32(txtEventMinutes.SelectedValue));
Line 143:            row["DisplayDate"] = dteDisplayDate.DateValue;
Line 144:            row.AcceptChanges();

Source File: c:\inetpub\Websites\\SectionControls\EventList.ascx.cs Line: 142

Stack Trace:

[FormatException: String was not recognized as a valid DateTime.]
   System.DateTimeParse.Parse(String s, DateTimeFormatInfo dtfi, DateTimeStyles styles) +2844850
   System.DateTime.Parse(String s) +25
   SectionControls_EventList.btnSaveDetails_Click(Object sender, EventArgs e) in c:\inetpub\Websites\\SectionControls\EventList.ascx.cs:142
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +110
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565

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

String was not recognized as a valid DateTime.

Mar 11, 2011 at 4:09 PM
Edited Mar 11, 2011 at 4:10 PM

Hi Richard,

Since I cannot reproduce the error locally you will need to debug your app. To do so, you must enable debugging in the web.config.

<compilation debug="true">

To set a breakpoint, go to the below line in EventList.ascx.cs and press F9.

row["EventDate"] = DateTime.Parse(txtEventDate.Text).AddHours(Convert.ToInt32(txtEventHours.SelectedValue)).AddMinutes(Convert.ToInt32(txtEventMinutes.SelectedValue)); //dteEventDate.DateValue.AddHours(Convert.ToInt32(txtEventHours.SelectedValue)).AddMinutes(Convert.ToInt32(txtEventMinutes.SelectedValue));

You will see a red dot appear to the left of the line number. When this code is executed, the process will halt until you tell it to continue.
See the Debug menu item for available commands. Step Into, Step Over and Continue will be the commands you would be using.

Now Hit F5 to start debugging your app. This will cause your app to recompile and will re-launch in to your default web browser.

Now go to your event list and add a new entry. This will execute the code to insert a new entry, but will halt at the breakpoint specified
(if the code is being executed). If you hover over the various control properties, for example txtEventDate.Text, it will show you the value being parsed.

This should help point you in the right direction.

For a more in-depth tutorial on debugging, see

Lastly, when in a production environment, always make sure to set debug to false. When in debug mode, you are loading additional code and compile times are increased.

Hope this helps.


Oct 26, 2011 at 10:57 PM

Did the OP ever find a fix for this?  I'm unable to use the Event Calendar due to this same error.  The date picked from the calendar is always dd-mm-yyyy and I always get an "Invalid date/time" error...


Nov 17, 2011 at 5:01 AM

Just made the change on the line 142 & it works smoothly!

Line 140:            row["EventLocation"] = txtEventLocation.Text.Trim();
Line 141: row["EventText"] = txtEventDescriptionHtml.Text.Trim();
Line 142: row["EventDate"] = dteEventDate.DateValue.AddHours(Convert.ToDouble(txtEventHours.SelectedValue)).AddMinutes(Convert.ToDouble(txtEventMinutes.SelectedValue));
Line 143: row["DisplayDate"] = dteDisplayDate.DateValue;
Line 144: row.AcceptChanges();