Sunday, May 15, 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:

Digg Technorati Delicious StumbleUpon Reddit BlinkList Furl Mixx Facebook Google Bookmark Yahoo
ma.gnolia squidoo newsvine live netscape tailrank mister-wong blogmarks slashdot spurl StumbleUpon

No comments:

Post a Comment

kbAlertz.com :: Visual Studio 2005

kbAlertz.com :: Visual Studio 2008

kbAlertz.com :: Visual Basic 2005