by Dennis Fisch (5 Submissions)
Category: Math/Dates
Compatability: Visual Basic 5.0
Difficulty: Intermediate
Date Added: Wed 3rd February 2021
Rating: (2 Votes)
This code takes a value of seconds as an input value and then calculates the duration in seconds, minutes, hours and days without using any VB date function. This code runs super fast. I wrote this for my IRC Server and thought it might be any useful for you... if you like it, you may want to vote, if not, well the not, i guess ;)
Public Function Duration(ByVal InSeconds As Long) As String
Dim Seconds As Long, mins As Long, Hours As Long, Days As Long
Seconds = InSeconds Mod 60
mins = (InSeconds \ 60) Mod 60
Hours = ((InSeconds \ 60) \ 60) Mod 24
Days = ((InSeconds \ 60) \ 60) \ 24
Duration = Days & " days " & Format$(Hours, "00") & ":" & Format$(mins, "00") &
":" & Format$(Seconds, "00")
End Function