Like it

Sunday, July 10, 2011

How to find Difference between two time (Dates) using VB.NET

Difference between two different dates using VB.NET

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:



No comments:

Post a Comment