DATEDIFF function will come handy to find the difference between a set of dates. The snippet given below gets the difference in seconds
Private Sub DateDiffExample()
Dim dt1 As Date = New Date(2011, 5, 15, 10, 11, 2)
Dim dt2 As Date = New Date(2011, 5, 15, 10, 12, 22)
Dim dt3 As Long = DateDiff(DateInterval.Second, dt1, dt2)
End Sub
You can tweak a bit to get for Minutes or Hours etc by
Private Sub DateDiffExample()
Dim dt1 As Date = New Date(2011, 5, 15, 10, 11, 2)
Dim dt2 As Date = New Date(2011, 5, 15, 10, 12, 22)
Dim dt3 As Long = DateDiff(DateInterval.Minute, dt1, dt2)
End Sub
Other useful links:
Validate Dates in VBA
No comments:
Post a Comment