ramya t

ramya t

  • NA
  • 130
  • 6.8k

String was not recognized as a valid DateTime.

Apr 25 2016 4:50 AM
hi
 
I was trying to calculate differences between two dates which is getting from textboxes.
 
my code is,
protected void Button1_Click(object sender, EventArgs e)
{
DateTime a = Convert.ToDateTime(t1.Text);
DateTime b = Convert.ToDateTime(t2.Text);
System.TimeSpan d = b.Subtract(a);
System.TimeSpan d1 = b - a;
string c = (b - a).TotalDays.ToString();

t3.Text = c.ToString();
}
after clicking a button  i am getting a error m as " String was not recognized as a valid DateTime.
"
Please help me to resolve this problem.

Answers (10)