How to find the time difference between 2 TimeSelector?

2

What I'm looking for is that when I select a specific time in each TimeSelector, I show the time difference between timeSelector1 and timeSelector2 in a textBox. I'm doing it this way:

  Dim h1, m1, h2, m2, totalm, totalh As Int16
    h1 = Convert.ToInt16(TimeSelector1.Hour)
    h2 = Convert.ToInt16(TimeSelector2.Hour)
    m1 = Convert.ToInt16(TimeSelector1.Minute)
    m2 = Convert.ToInt16(TimeSelector2.Minute)
    totalh = h2 - h1
    totalm = m2 - m1
    TextBox3.Text = totalh.ToString() + " : " + totalm.ToString() 

This way, the final hour with the initial time remains and the result is:

9: 15-10: 20 = 1: 5 there's no problem there

Now if the values are:

9: 20-9: 15 = 1: -5 The result is 1 hour and 5 minutes.

What I really should calculate is that they are 55 minutes apart.

    
asked by yulfredy rodriguez 02.06.2017 в 03:02
source

1 answer

0

In this way you can get the time difference between the two TimeSelector:

Dim horaInicio As DateTime = TimeSelector1.Date 
Dim horaFinal As DateTime = TimeSelector2.Date 
Dim diferencia As TimeSpan = horaFinal.Subtract(horaInicio)
TextBox3.Text = diferencia.ToString()
    
answered by 03.06.2017 в 00:57