Search code examples
c#asp.netformattingweb-configculture

Problem with Convert.ToDateTime in asp.net


I have an application that works without any problem in a spanish server.

When i uploaded the application into the online server (an english windows), im getting exceptions (of type "input string is not a valid Datetime/Int32") with Convert.ToDateTime and Convert.ToInt32. Are any web.config line that could help me in this matter? I tried adding a globalization element with the Spanish culture, but didnt worked.

Could you give me a hand?

Thanks in advance. Josema.


Solution

  • You need:

    System.Globalization.CultureInfo culture = 
                  new System.Globalization.CultureInfo("es-ES");
    DateTime myDateTime = Convert.ToDateTime(string, culture);