Hi,
I am using calender extender for 2 textboxes(txtstartdate,txtenddate) and have set the format as "dd/MM/yyyy". At the txtenddate textchanged event i am calculating no of days to diplay in txtduration.text..I am getting format exception like this:
String not recognised as valid datetime..
Where am i going wrong.. My code is as below
private int duration(string startdate, string enddate)
{
DateTime dt1= DateTime.Parse(startdate);
DateTime dt2= DateTime.Parse(enddate);
//dt1 = Convert.ToDateTime(txtstartdate.Text);
//dt2 = Convert.ToDateTime(txtenddate.Text);
TimeSpan ts = dt2.Subtract(dt1);
int days = ts.Days;
Session["days"] = days.ToString();
return days;
}
protected void txtenddate_TextChanged(object sender, EventArgs e)
{
int projectdays = duration(txtstartdate.Text, txtenddate.Text);
txtduration.Text = Convert.ToString(projectdays);
}