Thread: Adding Time
View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
kirkm[_9_] kirkm[_9_] is offline
external usenet poster
 
Posts: 14
Default Adding Time

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
--


I wanted it to handle various Minutes and Seconds formats and
it doesn't check for bad input as there shouldn't be any !