I have two textbox on my asp.net page which are taking dates from calendar control:
On Calendar selection, I am assigning the value of selected have to hidden variable.
below is the code:
DateTime dtOne;
dtOne = Convert.ToDateTime(hdnOne.Value.Trim().ToString());
DateTime dtTwo = Convert.ToDateTime(hdnTwo.Value.Trim().ToString());
When keeping breakpoint I get this value for dtOne
9/2/2011 02:03…
It is working fine in pre prod deployed site, but when I copy paste the same deployed code to the production I am getting below error:
System.FormatException: String was not recognized as a valid DateTime.
Any suggestion why it happened and how to resolve it?
The Culture settings on your server are most likely different from the one your development machine. In this case I would think the DateSeperator is the culprit.
Have you compared the value of hdnOne.Value.Trim().ToString() on both enviromnents?