Syntax for finding time difference?

andru

Newcomer
Joined
Nov 1, 2003
Messages
2
Hey guys, I'm new to VB.NET and really unfamiliar with the syntax.
I made one button, so when it's clicked, variable:
StartTime = Now

Similarly, another button when clicked is:
EndTime = Now

How do I find the elapsed time? i.e.
ElapsedTime = EndTime - StartTime?

I get the msg "Operator is not valid for type 'Date' and 'Date'."

Help this newbie with such a simple question please! :(
 
Visual Basic:
Dim startTime As Date = Date.Now
Dim endTime As Date

do something here
Dim i As Integer
For i = 1 To 10000
        Application.DoEvents()
Next
endTime = Date.Now

Dim diff As TimeSpan = endTime.Subtract(startTime)

MessageBox.Show(diff.TotalSeconds.ToString)
 
Not near VS.Net at the moment so I may be wrong but I thing the DateTime class can be created from a TimeSpan (I think it is one of the overload new methods).

Doing that will allow you to then use the dates .ToLongTime method.
 
Back
Top