adding time duration together

ninjaimp

Well-known member
Joined
Jun 13, 2007
Messages
80
Programming Experience
1-3
Hi

I have a small program that imports data and part of this data is in duration format:

00:00:00
(HoursMinutes,Seconds)


What im trying to do is add these together so that they show a cumalative duration, but im not at all sure how?
 
"Duration" is called "TimeSpan" in .Net, you add them with the + operator.
VB.NET:
Dim span1 As TimeSpan = TimeSpan.Parse("01:02:03")
Dim span2 As TimeSpan = TimeSpan.Parse("01:02:03")
Dim sum As TimeSpan = span1 + span2
 
this looks ideal but how do i assign it to a label or text box.

the reason i ask as i have this code:

VB.NET:
Dim time1 As TimeSpan = TimeSpan.Parse("00:00:03")
        Dim time2 As TimeSpan = TimeSpan.Parse("00:00:03")

        Dim sum As TimeSpan = time1 + time2

        lbltime1.Text = sum


and on the sum value assigned to bltime1 i get the build error:

value of type 'system.timespan' cannot be converted to 'string'
 
Look through the TimeSpan Members in help, see it there is anything you want there. In the end the ToString method is always a winner when it comes to getting the string representation of different data types.
 
Back
Top