Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Dim t1, t2, iMin As Integer, i As Integer, j As Integer
For j = 1 To 2
For i = 0 To 1
If i = 0 Then
Select Case j
Case 1
t1 = Split("120:15:00", ":")
iMin = t1(i) * 60
Case 2
t2 = Split("10:15", ":")
iMin = iMin + t2(i) * 60
End Select
Else
Select Case j
Case 1
iMin = iMin + t1(i)
Case 2
iMin = iMin + t2(i)
End Select
End If
Next
Next
MsgBox Int(iMin / 60) & ":" & iMin - Int(iMin / 60) * 60
So what does 120:15 + 10:15 mean?
You must be adding two DURATIONS, because it really does not make sense to ADD Two Time values.
I tested in excel and it can be done very simple
Private Function AddSubTime(stTim1 As String, stTim2 As String, SA As String) As String
'stTim1 is the first time as "hhh:mm" where hhh > 0 and mm = 0-59
'stTim2 is the second time as "hhh:mm"
'SA = A for adding: stTim1 + stTim2
'SA = S for substracting: stTim1 - stTim2
'Returns the Result of the operation as "hhh:mm" or "ERROR"
Dim X As Variant
Dim Y As Variant
Dim a, b, c, d, e, f As Long
If IsNull(stTim1) Then
MsgBox "Missing First Argument"
AddSubTime = "ERROR"
Exit Function
End If
X = Split(stTim1, ":")
a = CLng(X(0))
c = CLng(X(1))
If c > 59 Then '0 - 59
MsgBox "Error in First Argument"
AddSubTime = "ERROR"
Exit Function
End If
If IsNull(stTim2) Then
MsgBox "Missing Second Argument"
AddSubTime = "ERROR"
Exit Function
End If
Y = Split(stTim2, ":")
b = CLng(Y(0))
d = CLng(Y(1))
If d > 59 Then '0 - 59
MsgBox "Error in Second Argument"
AddSubTime = "ERROR"
Exit Function
End If
If SA = "A" Then 'Substracting or Adding
f = c + d 'We are Adding
e = 0
If f >= 60 Then
e = 1
f = f - 60
End If
AddSubTime = Trim(CStr(a + b + e)) & ":" & Trim(CStr(f))
Else 'We are Substracting
If a < b Then
MsgBox "First Argument must be greater than Second Argument"
AddSubTime = "ERROR"
Exit Function
End If
If c < d Then
a = a - 1
c = c + 60
End If
AddSubTime = Trim(CStr(a - b)) & ":" & Trim(CStr(c - d))
End If
End Function
'stTim1 is the first time as "hhh:mm" where hhh > 0 and mm = 0-59
'stTim2 is the second time as "hhh:mm"
'stDte1 is the first date as "mm:dd" where mm > 0 and dd = 0-29
'stDte2 is the second Date as "mm:dd"
Dim a, b, c, d, e, f As Long
Dim a As Long, b As Long, c As Long, d As Long, e As Long, f As Long