Google Групи вече не поддържа нови публикации или абонаменти в Usenet. Съдържанието за минали периоди остава видимо.

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

0 показвания
Преминаване към първото непрочетено съобщение

Dave

непрочетено,
4.06.2009 г., 6:20:014.06.09 г.
до
Hi, Does anyone know how this is possible?

Thanks

BruceM

непрочетено,
4.06.2009 г., 7:24:174.06.09 г.
до
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

непрочетено,
4.06.2009 г., 7:59:424.06.09 г.
до
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 нови съобщения