Convert seconds to time
For this purpose I made a function once.
After some minor alteration it may suit your needs.
Function TimeUnitsFromSeconds(ByVal lSeconds As Long) As Variant
'takes an integer number of seconds and gives a 1-D 0-based arrray
'with 4 elements.
'first element hours, second element minutes, third elements seconds
'fourth element will give the combined units as a string
'-------------------------------------------------------------------
Dim lSecs As Long
Dim lMinutes As Long
Dim lHours As Long
Dim strTime As String
Dim arr(0 To 3) As Variant
lHours = lSeconds \ 3600
lMinutes = (lSeconds - (lHours * 3600)) \ 60
lSecs = (lSeconds - (lHours * 3600)) - (lMinutes * 60)
arr(0) = lHours
arr(1) = lMinutes
arr(2) = lSecs
If arr(0) = 0 Then
If arr(1) = 0 Then
strTime = arr(2) & " seconds"
Else
If arr(2) = 0 Then
strTime = arr(1) & " minutes"
Else
strTime = arr(1) & " mins, " & arr(2) & " secs"
End If
End If
Else
If arr(1) = 0 Then
If arr(1) = 0 Then
strTime = arr(0) & " hours"
Else
strTime = arr(0) & " hrs, " & arr(2) & " secs"
End If
Else
If arr(2) = 0 Then
strTime = arr(0) & " hrs, " & arr(1) & " mins"
Else
strTime = arr(0) & " hrs, " & arr(1) & " mins, " & arr(2) &
" secs"
End If
End If
End If
arr(3) = strTime
TimeUnitsFromSeconds = arr
End Function
RBS
"Tod" wrote in message
...
Here is an easy one for somebody.
I have a list of seconds in duration, like this:
124
1256587
2354
60521
235325
Why they chose to do it this way, (?). I want to format
this to show in the typical h:mm:ss format.
How?
tod
|