Adding hours and minutes to timespan

How do you take hours and minutes that are in the form of 8.5( 8 hours 30 minutes ) for example and add it to an existing timespan.
Who is Participating?
1.Convert 8.5 hours string
 to HH:mm
it will be s="8:30"
 Dim vals() As String = s.Split(":")
2.create a tiem span
 Dim ts As New TimeSpan(CInt(vals(0)), CInt(vals(1)), 0)
3.add this time span to existing tiime span (ExistingTS)
     ExistingTS= ExistingTS.Add(ts)
Brian CroweDatabase AdministratorCommented:
dim dec as decimal = 8.5

myTimespan.add(new timespan(cint(dec.truncate), ((dec - dec.truncate) * 60).truncate, 0)
Fernando SotoRetiredCommented:
Hi jamesr1411;

This should do it.

        Dim DimExistingTS As New TimeSpan(1, 20, 0)
        Dim TimeToAdd As String = "8.5"
        Dim Hours As Integer = CType( _
            TimeToAdd.Substring(0, TimeToAdd.IndexOf(".")), Integer)
        Dim Minutes As Integer = CType(CType( _
            TimeToAdd.Substring(TimeToAdd.IndexOf(".")), Double) * 60, Integer)
        Dim ts As New TimeSpan(Hours, Minutes, 0)

        DimExistingTS = DimExistingTS.Add(ts)

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.