I am using Window 7, when I run my code in local everything is alright, but when upload to Window server 2003 the code will coming error:
“String was not recognized as a valid DateTime”
My computer setting (date format) all same with my window server. Still come out the same problem.
below is my code:
dateFrom = Convert.ToDateTime("12-6-2011");
dateTo = Convert.ToDateTime("18-6-2011");
//or
dateFrom = DateTime.ParseExact("12-6-2011", "MM/dd/yyyy", CultureInfo.InvariantCulture);
dateTo = DateTime.ParseExact("18-6-2011", "MM/dd/yyyy", CultureInfo.InvariantCulture);
//i using parse also din come out.
I do not know how this relates to the ‘C’ language, so I may have misinterpreted something. However, you are using the wrong format string as far as I can see.
If your dates always look like that, try using a format string like “d-M-yyyy”.
Have a look at the following page for reference: http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx