Calculate Elasped time help

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Good day,

I would like to capture the elapsed time down to the second. So far I have
two fields. One is timeStart and one is timeEnd. For example:

I have a time recorded say start = 00:00 and end = 00:56 for one particular
observation. I can have up to 50 observations. The next observation would be
from Start = 00:56 to whatever the end.

I am basiclly performing time & motion studies. At the end of the
observations I would like to sum the totals into a total time value in
munutes seconds.

Any help would be greatly appreciated.

Thanks in advance.
 
Don't use a Date type field to store durations: it isn't intended for that
purpose. Instead, use the DateDiff function to determine the number of
seconds between the two times (DateDiff("s", timeStart, timeEnd)) and simply
add uip the number of seconds. You may want to write a function that will
convert from total seconds to hh:mm:ss format:

Function FormatSeconds(DurationInSeconds As Long) As String
Dim lngHours As Long
Dim lngMinutes As Long
Dim lngSeconds As Long

lngHours = DurationInSeconds \ 3600
lngMinutes = DurationInSeconds Mod 3600
lngSeconds = lngMinutes Mod 60
lngMinutes = lngMinutes \ 60

FormatSeconds = lngHours & ":" & _
Format(lngMinutes, "00") & ":" & _
Format(lngSeconds, "00")

End Function
 
Douglas,

Thank you for youre time in helping me. I am new with coding.

First where would I put the DateDiff ? I am assuming in the query that my
report is based on?
Second. where would I but the convert function? In the query to?

Thanks I really really appreciate this help.
 
My recommendation would be to use the DateDiff function in the query.

The FormatSeconds function would be put in a stand-alone module in your
application. Unless you've got queries that are doing summations for you,
there's no reason to use that function in your query.
 
Hi Doug, I am not avhieving what I am trying to do. Not sure if it is the way
I have it set-up. So I am going to go throught it simply as I can and
hopefully I can be helped or clarified on this. So, I have two fields as
follows in my subform:

Name Data Type Format
Time_Start Date / Time Number
Time_End Date / Time Number

This is so I can enter my stop watch values as 0 for time start and for
example as a my time_end = 1.26 which would be 1 minute and 25 seconds. My
elapsed time would therefore be 85 Seconds total.

Is this possible to achieve an elapsed time?
 
Are you saying that you're actually entering 1.26 for Time_End? If so, your
Data Types shouldn't be Date/Time: a value of 1.26 for a date/time field
corresponds to 6:14:24 AM on 31 Dec, 1899.

You're going to need a function to convert from 1.25 to 85. Something like
the following untested air code, perhaps:

Function ConvertMinutesSeconds(Time_Value As Single) As Long

ConvertMinutesSeconds = Int(Time_Value) * 60 + _
(Time_Value - Int(Time_Value)) * 100

End Function
 
Back
Top