On Mon, 29 Nov 2004 05:22:25 GMT, Robert Schoenert <rs********@mindspring.com>
wrote:
I want to be able to subtract two time fields, one starting before
midnight and the other past midnight. example:
starttime 23:00 and endtime 01:10
The answer is 1:10.
How can I do this with all times on the 24 hour clock?
Easy. If you always know what the time direction should be, then any negative
number result needs to have 1 day added to it.
Public Function TimeDiff( _
StartTime As Variant, _
EndTime As Variant _
) As Variant
varTimeDiff As Variant
varTimeDiff = EndTime - StartTime
If varTimeDiff < 1 Then
varTimeDiff = varTimeDiff + 1.0 ' 1.0 = 1 day
End If
' CVDate in case data type is changed during computation.
TimeDiff = CVDate(varTimeDiff)
End Function