Adding Time

  • Thread starter Thread starter kirkm
  • Start date Start date
K

kirkm

Is there a command - or easy way to add minutes and seconds (rather
than converting everything to seconds etc.) ?

Thanks - Kirk
 
Answering my own question!
Did no one esle know, or was it so obvious as to be a silly
question ? :)

Anyway this seems to work, but there maybe some glitch
not envisaged. Any comments, criticisms welcome!

--

Function AddTimes(ByVal t1, t2)
'Adds MINS and SECS
' format "02:50" , "03 45", "4:33" etc

Dim t1s, t2s, tt
t1s = Split(t1, " ")
If UBound(t1s) <> 1 Then t1s = Split(t1, ":")
t2s = Split(t2, " ")
If UBound(t2s) <> 1 Then t2s = Split(t2, ":")
tt = TimeSerial(0, t1s(0), t1s(1)) + TimeSerial(0, t2s(0), t2s(1))

If Val(Format(tt, "hh")) = 0 Then
AddTimes = Format(tt, "nn:ss")
Else
AddTimes = Format(tt, "hh:nn:ss")
End If
End Function
 
Back
Top