Thanks
"Dave" <Da...@discussions.microsoft.com> wrote in message
news:D593A736-3277-4C2C...@microsoft.com...
From:
http://groups.google.com/group/microsoft.public.access/browse_frm/thread/be7e101c5176ebd8
'---Begin Module Code---
Public Function Seconds2DDHHNNSS(lngTotalSeconds As Long) As String
Dim intDays As Integer
Dim lngHours As Long
Dim intMinutes As Integer
Dim intSeconds As Integer
lngHours = lngTotalSeconds \ 3600
intDays = lngHours \ 24
lngHours = lngHours - intDays * 24
intMinutes = lngTotalSeconds \ 60 Mod 60
intSeconds = lngTotalSeconds Mod 60
Seconds2DDHHNNSS = Format(intDays, "00") & ":" & Format(lngHours, "00")
& ":" & Format(intMinutes, "00") & ":" & Format(intSeconds, "00")
End Function
Public Function DDHHNNSS2Seconds(strTime As String) As Long
Dim lngDays As Integer
Dim intHours As Integer
Dim intMinutes As Integer
Dim intSeconds As Integer
Dim intColon As Integer
intColon = InStr(1, strTime, ":", vbTextCompare)
lngDays = CLng(Left(strTime, intColon - 1))
intHours = CInt(MID(strTime, intColon + 1, 2))
intMinutes = CInt(MID(strTime, intColon + 4, 2))
intSeconds = CInt(Right(strTime, 2))
DDHHNNSS2Seconds = intSeconds + 60 * CLng(intMinutes + 60 *
CLng(intHours + 24 * lngDays))
End Function
Public Function AddDDHHNNSS(strTime1 As String, strTime2 As String) As
String
AddDDHHNNSS = Seconds2DDHHNNSS(DDHHNNSS2Seconds(strTime1) +
DDHHNNSS2Seconds(strTime2))
End Function
Public Function SubtractDDHHNNSS2Seconds(strTime1 As String, strTime2 As
String) As Long
SubtractDDHHNNSS2Seconds = DDHHNNSS2Seconds(strTime1) -
DDHHNNSS2Seconds(strTime2)
End Function
-----'End Module Code-----
Sample call:
Seconds2DDHHNNSS(SubtractDDHHNNSS2Seconds("01:08:05:08", "00:14:04:58"))
=> 00:18:00:10
Note that durations longer than about 68 years will cause a Long
variable containing seconds to overflow.
James A. Fortune
MPAP...@FortuneJames.com