How to add seconds to a time field
Brian Element
Forums
I had a member that wanted a one line solution on how to add seconds to a time field that was in character format. This is what I came up with. I also made it into a custom function if anyone else needs this functionality.
Option Explicit
Sub Main
Dim strTime As String
strTime = "11:59:24"
MsgBox addSeconds(strTime, "65")
End Sub
Function addSeconds(sTime As String, sIncrement As String) As String
If Not IsDate(sTime) Then
addSeconds = "Error"
Else
addSeconds = TimeSerial(Hour(sTime), Minute(sTime), Second(sTime) + CInt(sIncrement))
End If
End Function