fable fable - 1 month ago 6
ASP.NET (C#) Question

string was not recognized as a valid datetime after added datetimepicker

I have an error "string was not recognized as a valid datetime". I took this error when add "datetimepicker" in my project.
How can I solve this? I tried other solutions but didn't help.

Datetime garanti_baslangici = DateTime.Parse(
GarantiBaslangici.Text, System.Globalization.CultureInfo.InvariantCulture);


.aspx code

<asp:TextBox ID="GarantiBaslangici" CssClass="datepicker" runat="server" />

Answer

Try just parse string, it should parse right according to the current system format.

Datetime garanti_baslangici=DateTime.Parse(GarantiBaslangici.Text) 

or better

Datetime garanti_baslangici;
DateTime.TryParse(GarantiBaslangici.Text,garanti_baslangici);