Last post Oct 18, 2017 09:16 AM by Jayesh.Dalvi
Oct 18, 2017 05:16 AM|Jayesh.Dalvi|LINK
I have below value in textbox control in asp.net after selection of date from J Query Date Time Control.
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
Now I Want to get this value in DateTime Variable using asp.net so I can insert this value in the DataBase with datetime as data type column.
Now On ASPX Form in asp.net I tried below Code:
DateTime Dt = Convert.ToDateTime(TextBox1.Text);
Now After executing above line of code I get following error.
Additional information: String was not recognized as a valid DateTime.
Please help me to get "10/18/2017 06:21" TextBox1.Text value in the DateTime Dt variable so that i can remove below error and can insert the "10/18/2017 06:21"
value in database with datetime data type variable column like 2017-10-18 06:21:00.000
Oct 18, 2017 06:26 AM|Rajneesh Verma|LINK
Can you try as given below:
Oct 18, 2017 07:53 AM|Eric Du|LINK
According to your needs, please check the following sample code:
<asp:TextBox ID="datevalue" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
protected void Button1_Click(object sender, EventArgs e)
string date = datevalue.Text;
string newdate = date + ":00";
DateTime mynewDate = DateTime.Parse(newdate);
Oct 18, 2017 09:16 AM|Jayesh.Dalvi|LINK
I solved it by following line of information using asp.net c#.
You need to add
in your aspx form.
DateTime Dt = DateTime.ParseExact(TextBox1.Text, "MM/dd/yyyy HH:mm", CultureInfo.InvariantCulture);
Thank You Respected Eric Du,Rajneesh Verma Sir for your given information.