1

Im stuck here why i run my project in local properly but when i upload to server got this error.

i passing like this.

///////////////////in js///////////////////
'&dFrom='+Ext.getCmp('txtDateFrom').getValue().dateFormat('m/d/Y')
'dTo=' + Ext.getCmp('txtDateTo').getValue().dateFormat('m/d/Y')


///////////////////in c/////////////////////
 DateTime dFrom;
 DateTime dTo;
 dFrom = Convert.ToDateTime(Request.Params["dFrom"]);
 dTo = Convert.ToDateTime(Request.Params["dTo"]);
Pranay Rana
  • 175,020
  • 35
  • 237
  • 263
Choo Ken
  • 11
  • 2
  • This must be one of the most common questions here on SO. There are *at least* a handful of questions that must have popped up when you created your question (such as [this](http://stackoverflow.com/questions/1368064/system-formatexception-string-was-not-recognized-as-a-valid-datetime), [this](http://stackoverflow.com/questions/2193012/string-was-not-recognized-as-a-valid-datetime-format-dd-mm-yyyy) and [this](http://stackoverflow.com/questions/3044276/converting-string-to-valid-datetime). Did you check them? – Fredrik Mörk Apr 15 '11 at 10:27
  • possible duplicate of [Convert string to DateTime in c#](http://stackoverflow.com/questions/1592653/convert-string-to-datetime-in-c) – Fredrik Mörk Apr 15 '11 at 10:32

5 Answers5

2

This is a culture problem

try to use ParseExact:

DateTime.ParseExact(Request.Params["dFrom"], "MM/dd/yyyy", CultureInfo.InvariantCulture)

Hope this helps.

alexl
  • 6,841
  • 3
  • 24
  • 29
0

I was having this same problem, it was working locally as dd-mm-yy but after publishing my site to the server I got error: "String was not recognized as a valid DateTime" so I changed it to mm-dd-yy and it worked on the server but then locally I was getting the error, I'm assuming because my asp.net host is in USA so the server date format is different from here in Australia. So to fix this annoying problem I simply changed the date setting in my control panel to mm-dd-yy and now no more DateTime errors :)

Ben
  • 83
  • 8
0

Supply to convert culture(IFormatProvider). http://msdn.microsoft.com/en-us/library/9xk1h71t.aspx

VikciaR
  • 3,324
  • 20
  • 32
0

You might want to try using DateTime.Parse() instead of Convert.ToDateTime

DateTime dFrom = DateTime.Parse(Request.Params["dFrom"]);
DateTime dTo = DateTime.Parse(Request.Params["dTo"]);
lxalln
  • 930
  • 11
  • 29
  • ParseExact with the culture information is probably a better answer than this, see alexl's answer – lxalln Apr 15 '11 at 10:25
0

You could try DateTime.Parse(string) and see if it gets a better result, otherwise the GET-string should be in another format. Also the CurrentCulture could modify the output.

Bas
  • 26,772
  • 8
  • 53
  • 86