Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Conversion from string "31/03/2012" to type 'Date' is not valid

My web app is running perfectly in asp vb.net editor. But when i run my web app through IIS7 then i get this error. What am i missing in configuring IIS7? Is there anyone who can suggest something?

Thanks in Advance

like image 735
Dev Avatar asked Jun 15 '26 14:06

Dev


2 Answers

Because your IIS7 is configured for the English Language and that date is probably Italian or something similar. You'll have to tell to the Date.Parse which culture to use.

Something like

dateValue = Date.Parse(yourDate, CultureInfo.CreateSpecificCulture("it-IT"))

Or you can change the culture in your IIS7

Here there are the instructions

for example if you use the UI

Using the UI Open IIS Manager and navigate to the level you want to manage. (omissis)

In Features View, double-click .NET Globalization.

On the .NET Globalization page, in the property sheet, click to select the global setting you want to edit, and select a value from the drop-down list.

In the Actions pane, click Apply.

Or you could set the culture of your app in the web.config

<system.web>
    <globalization culture="it-IT" uiCulture="it-IT"/>
</system.web>
like image 119
xanatos Avatar answered Jun 19 '26 19:06

xanatos


If you are sure that the date is always in exactly that format, then you can use ParseExact instead:

var date = DateTime.ParseExact(
               "31/03/2012",
               "dd/MM/yyyy",
               System.Globalization.CultureInfo.InvariantCulture);
like image 33
M4N Avatar answered Jun 19 '26 18:06

M4N



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!