borderAndreaVB free resources for Visual Basic developersborder
AndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2017 Andrea Tincani
:: Calculate the Elapsed Time between two Dates...

Author  

Herry Hariry Amin

Language  

VB4, VB5, VB6

Operating Systems  

Windows 95, 98 and NT
Module

Option Explicit

Public Function ElapsedTime(tStart, tStop) As String
' *******************************************************************
' Function Name : ElapsedTime *
' Created By : Herry Hariry Amin *
' Email : h2arr@cbn.net.id *
' Language : VB4, VB5, VB6 *
' Example : sYourVariable = ElapsedTime(tStartTime,tStopTime) *
' *******************************************************************


    Dim dtr, dtl, jml As Long

    dtl = (Hour(tStart) * 3600) + (Minute(tStart) * 60) + (Second(tStart))
    dtr = (Hour(tStop) * 3600) + (Minute(tStop) * 60) + (Second(tStop))
    If tStop < tStart Then
        jml = 86400
    Else
        jml = 0
    End If
    jml = jml + (dtr - dtl)
    ElapsedTime = Format(Str(Int((Int((jml / 3600)) Mod 24))), "00") + ":" + Format(Str(Int((Int((jml / 60)) Mod 60))), "00") + ":" + Format(Str(Int((jml Mod 60))), "00")
End Function

Usage

Private Sub Command1_Click()
    MsgBox ElapsedTime(Now, Now - 0.512)
End Sub

:: Navigation

Home

Beginners Corner

Next Tip

:: Search this site
Google
:: Related Topics
icon 05-01-2006 Re: Store the log in & log out time of a user in a database by Dave Green
icon 22-02-2005 Re: repeat/hold button? by Goran
icon 25-02-2003 Re: TIMER QUESTION!!! by yronium
borderAndreaVB free resources for Visual Basic developersborder
borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2017 Andrea Tincaniborder