How can I format a Date Difference in C# using timespan.subtract
Here is what I have so far, I need it to return in hh:mi format
If there is an easier way to do it other than timespan im open to it. I just have to return this to the user in an hh:mi format. Even (negative times) -hh:mi if the time returned is negative.
Thanks
DateTime startTime = new DateTime(); DateTime endTime = new DateTime(); TimeSpan conflictDuration = new TimeSpan();startTime = 03/28/2011 11:45;endTime = 03/28/2011 1:47;conflictDuration = endTime.Subtract(startTime);
There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.
Mike TomlinsonMiddle School Assistant TeacherCommented:
Woohoo! Thanks for update wdosanjos. =)
You have to escape the ":" though like this:
Dim dtA As DateTime = DateTime.Now Dim dtB As DateTime = dtA.AddDays(Math.PI) Dim ts As TimeSpan = dtB.Subtract(dtA) Label1.Text = ts.ToString("dd\:hh\:mm\:ss")