Apiz Zest
Apiz Zest

Reputation: 37

String was not recognized as a valid Date Time error on IIS

Greeting people...i develop a web..everything working fine till deployment...my question is - why is it this error appear? because if i run the web on Visual Studio Server everything fine...but when i deploy and run it on IIS server suddenly this error appear..why is people? really need some help here..

string tarikh = Convert.ToDateTime(txtTarikh.Text).ToString("yyyy-MM-dd");

the line is where the cause of error..thanks in advance

Upvotes: 1

Views: 7392

Answers (6)

Prince Prasad
Prince Prasad

Reputation: 1678

<system.web>
    <globalization requestEncoding="utf-8"  responseEncoding="utf-8" fileEncoding="utf-8" culture="en-US" uiCulture="en-US" />
  </system.web>

change these lines in web.config and publish it again.. It worked for me.

Upvotes: 0

nad sid
nad sid

Reputation: 21

enter image description here

Issue is resolved by setting up .net globlization settings in IIS

Upvotes: 1

Vikram Gharge
Vikram Gharge

Reputation: 187

For this problem you have to go to the IIS

Go to IIS -> Select your Configured Website -> Click on .NET Globalization

From .NET Globalization, select Culture and UI- Culture as English (United State) (en – US)

Restart IIS by running command as iisreset through windows command prompt

Check application is giving same problem or not

Upvotes: 6

Dan Bystr&#246;m
Dan Bystr&#246;m

Reputation: 9244

You have different "regional setting" on your development machine and the web server.

Instead of calling Convert.ToDateTime(string), you could try to use the overloaded version Convert.ToDateTime(string, IFormatProvider) and specify in what format you expect the date to be in.

Some of us thinks that today's date is "2012-04-22" while other claims it is "4/22/2012" etc...

EDIT: Just do something like:

var  ci = new CultureInfo("xx-XX");
var dateTime = Convert.ToDateTime(txtTarikh.Text, ci);

Where xx-XX is the code of the culture you want to work with. Look it up here: http://sharpertutorials.com/list-of-culture-codes/

Upvotes: 2

Jon Skeet
Jon Skeet

Reputation: 1502016

Chances are the server-side default culture is different to the one you've been using in development.

What format are you expecting the date to be in, anyway? You should either use DateTime.TryParseExact or at least use DateTime.TryParse specifying the appropriate CultureInfo. (For example, the culture of the user.)

Likewise I would suggest that you supply an appropriate CultureInfo to ToString - possibly CultureInfo.InvariantCulture.

Upvotes: 2

Nesim Razon
Nesim Razon

Reputation: 9794

Because the date you get from txtTarikh.Text is not parsed as date. Probably on your local machine, your regional settings are different from your server. Add a log and print txtTarikh.Text to see what returns at your server and also on your local machine.

Upvotes: 1

Related Questions