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
A Demo Application To Find Time Diference in Am and Pm Dates.
ReplyDeleteYou can easily download it from here . Here is also code and explanation
http://geeksprogrammings.blogspot.in/2013/07/program-to-find-date-difference-visual.html