Advertisement
C_Volume2 Math/ Dates #75361

Time Difference

Displays the difference between two times in Hours Minutes and seconds

AI

AI 摘要: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

源代码
original-source
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
原始评论 (3)
从 Wayback Machine 恢复