Asp.net+VB+SQL After Migrating from 2012 to 2019 Server getting Date error

Baiju EP 141 Reputation points
2022-08-23T04:41:59.783+00:00

Asp.net+VB+SQL website it was working in 2012 but after migrating to 2019 server I am getting error.

233809-whatsapp-image-2022-08-23-at-100544-am.jpeg

Now I am using Win Server 2019

233856-whatsapp-image-2022-08-23-at-100543-am.jpeg

This date error I am getting now. I had tried to change the date format in new server 2019 but still I am getting same error.
233886-whatsapp-image-2022-08-23-at-100544-am-1.jpeg

Developer technologies ASP.NET Other
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Lan Huang-MSFT 30,186 Reputation points Microsoft External Staff
    2022-08-23T08:31:28.403+00:00

    Hi @Baiju EP ,

    String was not recognized as a valid DateTime

    As described in the error, the string is not recognized as a valid datetime.
    It may be because the server sets the datetime format at the time of installation (UK format 'dd-mm-yyyy', US format 'mm-dd-yyyy'.
    You need to define the culture you wish to use in the web config:

    <configuration>  
       <system.web>  
          <globalization culture="en-GB"/>  
       </system.web>  
    </configuration>  
    

    You can also use DateTime.ParseExact() method.
    https://learn.microsoft.com/en-us/dotnet/api/system.datetime.parseexact?redirectedfrom=MSDN&view=net-6.0#System_DateTime_ParseExact_System_String_System_String_System_IFormatProvider_

    Converts the specified string representation of a date and time to its DateTime equivalent using the specified format and culture-specific format information. The format of the string representation must match the specified format exactly.

    For example:

    DateTime date = DateTime.ParseExact(this.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture);  
    

    Best regards,
    Lan Huang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.