VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Time Difference

by Onisan (1 Submission)
Category: Math/Dates
Compatability: Visual Basic 5.0
Difficulty: Advanced
Date Added: Wed 3rd February 2021
Rating: (2 Votes)

Displays the difference between two times in Hours Minutes and seconds

Inputs
Start time and End Time
Code Returns
Returns time as HH:NN:SS

Rate Time Difference

Sub Test()
          'Start Time, End Time
  MsgBox TimeDiff("11:34:29", "20:32:20")
End Sub

Function TimeDiff(STime As Date, ETime As Date) As Date
Dim TimeSecs, Hrs As Double
  'Get Total Number of seconds difference
  TimeSecs = DateDiff("S", STime, ETime)
  
    'If Difference is a minus(-), add 24 hours worth of seconds.
    If TimeSecs <> Abs(TimeSecs) Then: TimeSecs = TimeSecs + 86400
   
    'If there are hours get them here
    If TimeSecs >= 3600 Then: Hrs = Fix(TimeSecs / 3600)
    TimeDiff = TimeSerial(Hrs, 0, TimeSecs - (Hrs * 3600))
End Function

Download this snippet    Add to My Saved Code

Time Difference Comments

No comments have been posted about Time Difference. Why not be the first to post a comment about Time Difference.

Post your comment

Subject:
Message:
0/1000 characters