Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calculate the total amount of elapsed time in hours

Status
Not open for further replies.

487Jack

Technical User
Jul 5, 2007
2
US
I am trying to calculate the total amount of time in hours that it takes to complete a test. I had two fields in my table called:

StartTime
EndTime

I than used the following formula to calculate the total time:

=Format([StartTime] -1 -[EndTime]’ “ShortTime”)

This formula works find. But some of the test that I run can run for days or even weeks. I then added two additional fields to my table to capture the start date of the test and end date of the test:

StartDate
EndDate

Is there a way to calculate the total test time in hours using the StartDate and StartTime and EndDate and EndTime?

Your help would be greatly appreciated.

Thank you,
Stephen Jones
 

Code:
StartDT = Me.StartDate & " " & Me.StartTime

EndDT = Me.EndDate & " " & Me.EndTime

Me.TotalTestTime = DateDiff("n", StartDT, EndDT) / 60

will give you the total hours in hours and fraction of an hour. Depending on your particular needs, you may want to round TotalTestTime.

The Missinglinq

Richmond, Virginia

There's ALWAYS more than one way to skin a cat!
 
Thank you very much for your response. I should have mention that I am beginner with access and I that have never written code before. If you could tell me were to enter the code I should be able to figure it out from there.

Thank you,
Stephen Jones
 



"I had two fields in my table..."

Date/Time values are NUMBERS.
Code:
Me.TotalTestTime = ([EndDate]+[EndTime])-([StartDate]+[StartTime]) / 60
[code]


Skip,
[sub]
[glasses]Just traded in my old subtlety...
[b]for a NUANCE![/b][tongue][/sub]
 
oops...

"I had two fields in my table..."

Date/Time values are NUMBERS.
Code:
Me.TotalTestTime = ([EndDate]+[EndTime])-([StartDate]+[StartTime]) * 24


Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
You probably could've just kept the 2 fields with a format of general date to capture both date and time.

I believe you are trying to achieve something like this:

start end total
10/10/08 10:00:00 AM 10/11/08 10:00:00 AM 24.00
10/11/08 10:00:00 AM 10/11/08 9:00:00 PM 11.00

To do so, in you query, use formula:

([end]-[start])*24

HTH
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top