TimeSpan

  • Thread starter Thread starter Nigel Findlater
  • Start date Start date
N

Nigel Findlater

Hallo Everyone,

I would like to find the difference in seconds between 2
times. So I did the following:

Dim x1 As DateTime = #5/26/2003 11:53:00 AM#
Dim x2 As DateTime = #5/26/2003 11:54:00 AM#
Dim TS1 As TimeSpan
TS1 = x2.Subtract(x1)
MessageBox.Show(TS1.Seconds.ToString)

But I end up with 0 and not 60 s

What did I do wrong?

Nigel...
 
The difference is 1 minute and 0 seconds so the output is correct.
You should use the TotalSeconds property, this will be 60.

Peter
 
Thanks, this worked.

I think I was programming to long and could not see the
wood for the trees

have a nice evening...

Nigel...
 
Nigel Findlater said:
I would like to find the difference in seconds between 2
times. So I did the following:

Dim x1 As DateTime = #5/26/2003 11:53:00 AM#
Dim x2 As DateTime = #5/26/2003 11:54:00 AM#
Dim TS1 As TimeSpan
TS1 = x2.Subtract(x1)
MessageBox.Show(TS1.Seconds.ToString)

But I end up with 0 and not 60 s

What did I do wrong?

You used Seconds instead of TotalSeconds. The Seconds property always
returns between 0 and 59 inclusive. For instance, for a TimeSpan of 90
seconds, Seconds would return 30 and Minutes would return 1.
 
Back
Top