Click here to Skip to main content
15,919,423 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
DateTime dt1 = Convert.ToDateTime(txtEndDate.Text);
DateTime dt2 = Convert.ToDateTime(txtStartDate.Text);
TimeSpan ts = dt1.Subtract(dt2);
TextBox1.Text = ts.ToString();
Posted
Updated 21-Feb-13 22:57pm
v2

TextBox1.Text = ts.ToString("HH:mm", CultureInfo.InvariantCulture) might be what you're looking for.

Hope this helps,
Fredrik
 
Share this answer
 
If you are using .NET 4.0, you can simply format TimeSpan[^].
In earlier versions you can create new DateTime from that TimeSpan instance (ts) and format DateTime[^].
 
Share this answer
 
Here is a good link that has the different formats you can use to show your result for date or time also.

Date Time format

There is only a way for your question t o format the result based on requirement.

Thanks
 
Share this answer
 

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