fable fable - 2 months ago 9
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" />


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;