Tools Links Login

Time Between Dates

Calculate the time elapsed between two dates.

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

About this post

Posted: 2019-08-24
By: HerryHariryAmin
Viewed: 208 times

Categories

Visual Basic 6

Attachments

No attachments for this post

Special Instructions

This code originally appeared on AndreaVB.com, and has been republished here with the permission of Andrea Tincani.


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.