Function TimeConversion(ByVal dteTime As Date) As String
On Error GoTo TimeConversion
' Author: Mile-O-Phile
' Discussion: This function is designed to take a sum of times, which Access would return as a
' 24-Hour clock value i.e when 23:59:59 has two seconds pass by, rather than the result
' be 24:00:01, Access would return 00:00:01. This function remedies this and returns the
' correct result as a string which can be used for display purposes only.
' Input(s): dteTime - the sum of time values that the user wishes to convert
' Process: change the given time from the constraints of the 24-Hour clock
' fix minute and second values that may contain single number values ie. 0-9
' eliminate any spaces that may form from string conversion
' Output(s): TimeConversion- the given time translated beyond the 24-Hour clock i.e 179:34:07
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