Does anyone know if there is a function for a query to add up minutes and seconds. My database contains records of music album tracks with duration for each track. I just want to add up the minutes and seconds of a selected number of tracks.
namliam said:you can "simply" sum/add date/time fields as you would any "normal" number field.....
10:15 + 5:15 + 15:30+ 30:00 = 1:00:00
Hmz, i started to post that would be a format thing. but looking again it seems it not posible to have 25:00:00. Where i seem to remember doing that somewhere ... something like Format(,"hhh:nn:ss") but that dont seem to workMile-O-Phile said:
If you only have times then summing them works on a 24 hours clock - you need to then convert the number of days into hours, too.
namliam said:Hmz, i started to post that would be a format thing. but looking again it seems it not posible to have 25:00:00. Where i seem to remember doing that somewhere ... something like Format(,"hhh:nn:ss") but that dont seem to work
Regards
Function TimeConversion(ByVal dteTime As Date) As String
On Error GoTo TimeConversion
Dim lngDays As Long, lngHours As Long, lngMinutes As Long, lngSeconds As Long
Dim intCounter As Integer, strTemp As String
' using the 'Csng' function, convert the given time to broken down values
lngDays = Int(CSng(dteTime))
lngDays = lngDays * 24 ' turn number of days to hours
lngHours = Int(CSng(dteTime * 24))
lngMinutes = Int(CSng(dteTime * 1440))
lngSeconds = Int(CSng(dteTime * 86400))
lngHours = lngDays + (lngHours Mod 24) ' calculate total of hours
lngMinutes = lngMinutes Mod 60 ' get actual minutes
lngSeconds = lngSeconds Mod 60 ' get actual seconds
' fix single figure values for minutes, i.e change :5 to :05
Select Case lngMinutes
Case Is = 0
strTemp = Str(lngHours) & ":00"
Case Is < 10
strTemp = Str(lngHours) & ":0" & lngMinutes
Case Else
strTemp = Str(lngHours) & ":" & Str(lngMinutes)
End Select
' fix single figure values for seconds, i.e change :5 to :05
Select Case lngSeconds
Case Is = 0
strTemp = strTemp & ":00"
Case Is < 10
strTemp = strTemp & ":0" & Str(lngSeconds)
Case Else
strTemp = strTemp & ":" & Str(lngSeconds)
End Select
' the 'Str()' function may append spaces to the newly formed string, this loop eliminates these
For intCounter = 1 To Len(strTemp)
If Mid(strTemp, intCounter, 1) = " " Then
' do nothing
Else
TimeConversion = TimeConversion & Mid(strTemp, intCounter, 1)
End If
Next intCounter
Exit_TimeConversion:
Exit Function
Err_TimeConversion:
MsgBox Err.Number & Err.Description
Resume Exit_TimeConversion
End Function
raskew said:You're strangely silent here.
Sure you don't want to jump back in and increment your total number of posts? Maybe 'oops' would be appropriate.