A difference between two DateTimes
returns a TimeSpan
object. You can either use the Subtract
method of DateTime
or even use -
. You have to use the subtract the earlier date from the later date:
Dim span As TimeSpan = dtpEnd.Value - dtpStart.Value
You can use the Duration
method to get an absolute timespan, then the order doesn't matter:
Dim duration As TimeSpan = (dtpStart.Value - dtpEnd.Value).Duration()
If you for example want the number of minutes between, use the TotalMinutes
property:
Dim minutes As Int32 = CInt(duration.TotalMinutes)