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.