Click here to Skip to main content
15,867,704 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Everyone,

i am trying to parse a date time to a text box but it give the error below;

System.FormatException: String was not recognized as a valid DateTime. at System.DateTimeParse.Parse(String s, DateTimeFormatInfo dtfi, DateTimeStyles styles) at System.DateTime.Parse(String s) at Administration_Manage_Members_FormsView_MemberPlan.btnSubmit_Click(Object sender, EventArgs e)

here is the code i used;
C#
DateTime dttxtInceptionDate = DateTime.Parse(txtInceptionDate.Text.Trim());

Thanks for your help....
Posted
Updated 15-Jul-13 22:41pm
v2
Comments
Johnny J. 16-Jul-13 4:26am    
If chimchams solution is not helping you, then we need to know what text you enter in txtInceptionDate.Text...
johannesnestler 16-Jul-13 8:26am    
If you still interested in an answer just post the TEXT you entered in the TextBox (isn't it obvious that the error is there? - your parsing code is irrelevant). Most likely you have a culture problem and need to parse with a specific and not your current system culture

Hi, try to use this:

C#
string date = txtInceptionDate.Text;
DateTime dttxtInceptionDate = Convert.ToDateTime(date);


OR

C#
string date = txtInceptionDate.Text;
DateTime dttxtInceptionDate = DateTime.Parse(date);
 
Share this answer
 
Comments
Nkhanedzeni 16-Jul-13 4:27am    
thanks, let me try...
Nkhanedzeni 16-Jul-13 4:39am    
Hi Chimcham... it gives this kind of the error again

System.FormatException: String was not recognized as a valid DateTime. at System.DateTimeParse.Parse(String s, DateTimeFormatInfo dtfi, DateTimeStyles styles) at System.DateTime.Parse(String s) at Administration_Manage_Members_FormsView_MemberPlan.btnSubmit_Click(Object sender, EventArgs e)
berrymaria 16-Jul-13 4:42am    
what is the value of you txtInceptionDate.Text ?
Nkhanedzeni 16-Jul-13 4:47am    
date input....

here is the format i used under the grid view;

foreach (MCX.FASNew.BaseDALC.Plan.VMemberPlanDetails _vGetvMemberPlanList in _vGetvMemberPlan)
{

txtInceptionDate.Text = String.Format("{0:dd/MM/yyyy}", _vGetvMemberPlanList.InceptionDate);
CboMemberName.SelectedValue = _vGetvMemberPlanList.MemberID.ToString();
CboPlanName.SelectedValue = _vGetvMemberPlanList.PlanID.ToString();
ViewState["MemberPlanID"] = _vGetvMemberPlanList.MemberPlanID.ToString();

}

then under the button i used your codes;

protected void btnDelete_Click(object sender, EventArgs e)
{
string date = txtInceptionDate.Text;
DateTime dttxtInceptionDate = DateTime.Parse(date);

//DateTime dttxtInceptionDate1 = DateTime.Parse(txtInceptionDate.Text.Trim());
_daPlan.InsertMemberPlan(3, int.Parse(ViewState["MemberPlanID"].ToString()), int.Parse(CboMemberName.SelectedValue), int.Parse(CboPlanName.SelectedValue), true, dttxtInceptionDate);
FetchData();
ViewState["MemberPlanID"] = "";
txtInceptionDate.Text = "";
CboPlanName.SelectedIndex = 0;
CboMemberName.SelectedIndex = 0;
}
we need to know what text you are entering in txtInceptionDate.Text.

use Convert.ToDateTime
 
Share this answer
 
Comments
Nkhanedzeni 16-Jul-13 5:18am    
i have already use Convert.ToDate....

date e.g 27/12/2011

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900