How to get the Time difference
Hi Guys,
I would like to know how we can get the time difference in hours in C#.
Eg.
If i have a time A) 11:22 and B) 21:22
I need to know the difference between B and A with + ve or -ve diff.
That is A - B = - 10
Always this is my order of executiton ( A - B).
Awaiting a response.
Thanks,
Sunil.
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.

Scott LysleRank #49 · 31K reputationPosted May 14, 2007, 8:45 PM EDT
TimeSpan
ts = new TimeSpan();ts = DateTime.Now - dtp1.Value; MessageBox.Show(ts.Hours.ToString() + " hours, " +
ts.Minutes.ToString() + " minutes, and " +
ts.Seconds.ToString() + " seconds", "Time Difference");