Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to sum hours, mins, secs (00:00:00)?

0 views
Skip to first unread message

Dave

unread,
Jun 4, 2009, 6:20:01 AM6/4/09
to
Hi, Does anyone know how this is possible?

Thanks

BruceM

unread,
Jun 4, 2009, 7:24:17 AM6/4/09
to
Is this a question pertaining to Microsoft Access? If so, you need to
provide some detail such as how the data are stored, and what you mean by
"add". Adding total elapsed time? Combining three fields into one
displayed value?

"Dave" <Da...@discussions.microsoft.com> wrote in message
news:D593A736-3277-4C2C...@microsoft.com...

James A. Fortune

unread,
Jun 4, 2009, 7:59:42 AM6/4/09
to
Dave wrote:
> Hi, Does anyone know how this is possible?
>
> Thanks

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

0 new messages