Hi Vinaysrk
The TimeSpan.Parse() method accepts strings representing timespans, not dates. The format for timespans is documented here on MSDN:
TimeSpan.Parse Method (String)
I notice also in line 4 of your code you're attempting to assign a TimeSpan to a string. You'll get a "Cannot implicitly convert type" error message at compile time.
Assuming date1 and date2 actually contain dates, I think your code should use the DateTime structure and look something like this:
DateTime date1 = DateTime.Parse(TextBox1.Text);
DateTime date2 = DateTime.Parse(TextBox2.Text);
TimeSpan ts = date1 - date2;
TextBox3.Text = ts.ToString(); DateTime.Parse will thow exceptions if an invalid date is entered, so you'll want to catch this, unless you're 100% sure the user is never going to enter an invalid date.
LaxLoafer
Junior Poster in Training
68 posts since Aug 2011
Reputation Points: 43
Solved Threads: 12