none
Datetime parsing issue RRS feed

  • Question

  • .NET framework is unable to parse date from dd.MMM.yyyy format in when culture is set to "it-IT" on Windows server 2012. Any workaround to fix this issue. I have to use the "dd.MMM.yyyy" format?

    Thanks in advance

    Monday, July 6, 2015 9:57 AM

Answers

  • You could try the ParseExact method:

    string date = "6.LUG.2015";
    DateTime dt = DateTime.ParseExact(date, "d.MMM.yyyy", new CultureInfo("it-IT"));
    
    string date = "12.07.2015";
    DateTime dt = DateTime.ParseExact(date, "d.M.yyyy", new CultureInfo("it-IT"));
    

    Make sure that the value of your date string is what you expect.

    Hope that helps.

    Please remember to close your threads by marking helpful posts as answer and then start a new thread if you have a new question. Please don't ask several questions in the same thread.

    Tuesday, July 7, 2015 11:51 AM

All replies

  • This works:

    string date = "12.07.2015";
    DateTime dt = DateTime.Parse(date, new CultureInfo("it-IT"));

    And this works as well:

                string date = "6.LUG.2015";
                DateTime dt = DateTime.Parse(date, new CultureInfo("it-IT"));

    Please provide a reprodicable code sample if you want any further help.

    Please also remember to close your threads by marking helpful posts as answer and then start a new thread if you have a new question. Please don't ask several questions in the same thread.

    Monday, July 6, 2015 10:41 AM
  • many thanks for help,

    Did you tried the same code on Windows Server 2012, as my application is a web mvc application, hosted on a windows server 2012, i tried code suggested by you too, using a windows application and ran it on server, but no success and following error was returned;

    "String was not recognized as valid date time."

    Thanks

    Tuesday, July 7, 2015 4:48 AM
  • You could try the ParseExact method:

    string date = "6.LUG.2015";
    DateTime dt = DateTime.ParseExact(date, "d.MMM.yyyy", new CultureInfo("it-IT"));
    
    string date = "12.07.2015";
    DateTime dt = DateTime.ParseExact(date, "d.M.yyyy", new CultureInfo("it-IT"));
    

    Make sure that the value of your date string is what you expect.

    Hope that helps.

    Please remember to close your threads by marking helpful posts as answer and then start a new thread if you have a new question. Please don't ask several questions in the same thread.

    Tuesday, July 7, 2015 11:51 AM