this is the code which I found online and works great. I forgot its author but whoever you are, 10x but a lil help would be appreciated...
here is the code
both return positive value. he had commented this line as "returns postive no matter what
but i can't seem to figure out which part of it makes Res positive always.
any tips?
here is the code
Code:
'public variables
Const MSecInSec As Double = 1000
Const SecsInMin As Double = 60
Const MinsInHour As Double = 60
Const HoursInDay As Double = 24
Const SecsInDay As Double = HoursInDay * MinsInHour * SecsInMin
Const mSecMult As Double = 1 / (SecsInDay * MSecInSec)
private sub command1_click()
msgbox ReturnTimeDifference("01:00:00:00","04:30:00:00")
msgbox ReturnTimeDifference("04:00:00:00","01:30:00:00")
end sub
Public Function ReturnTimeDifference(ByVal smalltime As String, ByVal bigtime As String) As String
Dim TimeA As Date
Dim TimeB As Date
Dim Res As Double
Dim timeparts As Variant
Dim timepartsb As Variant
Dim ms As String
Dim ms2 As String
timeparts = Split(smalltime, ":")
timepartsb = Split(bigtime, ":")
ms = timeparts(3)
ms2 = timepartsb(3)
ms = ms & String(3 - Len(ms), "0")
ms2 = ms2 & String(3 - Len(ms2), "0")
TimeA = TimeSerialEx(timeparts(0), timeparts(1), timeparts(2), ms) '01:04:12.2
TimeB = TimeSerialEx(timepartsb(0), timepartsb(1), timepartsb(2), ms2) '05:08:15.55
Res = Format$((TimeB - TimeA) * SecsInDay, "0.00") 'RETURNS POSITIVE NO MATTER WHAT!
ReturnTimeDifference = Format$(Res / SecsInDay, "hh:nn:ss:") & _
Round(Res - Fix(Res), 2) * 100 'avoids the decimal point
End Function
Code:
Res = Format$((TimeB - TimeA) * SecsInDay, "0.00") 'RETURNS POSITIVE NO MATTER WHAT!
any tips?
Comment