Hi All,
Hopefully I am being dumb here, I have tried a few alternatives and all come to the same result.
In our application there are certain fields that allow a user to type in a date (which we check for validity) that is used within a calculation. When I host the application either withing Visual Studio or IIS it works fine with either of the following code:
Code:
DateTime.Parse("20/07/1978");
or
Code:
DateTime parsedDate;
DateTime.TryParse("20/07/1978", out parsedDate);
or indeed
Code:
Convert.ToDateTime("20/07/1978"));
But whenever I run even your sample app and add the following a line of code in like the one below for instance:
Code:
this.Label1.Text += string.Format("Converted Date To: {0}", DateTime.Parse("20/07/1978"));
I get the following error:
Quote:Server Error in '/' Application.
Could not determine the order of year, month, and date from '"dd/MM/yyyy"'.
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: Could not determine the order of year, month, and date from '"dd/MM/yyyy"'.
Source Error:
Line 14: {
Line 15: this.Label1.Text = string.Format("Page served by: {0}", this.Request.ServerVariables["SERVER_SOFTWARE"]);
Line 16: this.Label1.Text += string.Format("Converted Date To: {0}", DateTime.Parse("20/07/1978"));
Line 17: //this.Label1.Text += string.Format("Converted Date To: {0}", Convert.ToDateTime("20/07/1978"));
Line 18: }
I have tried putting the following in the web.config:
Code:
<globalization culture="en-GB" uiCulture="en-GB" requestEncoding="utf-8" responseEncoding="utf-8" />
To force the system to use UK culture for the formatting but I still get the same error.
Can anyone point me in the right direction, is there something blatantly obvious that I am missing?
Best wishes
Lee