Adding Total Hours for the Week

G

Guest

I have seven fields in a record to record hours. Each field is defined as a
Date/Time field with a Format of Short Date with the Mask of a short date.

I want to add these seven field together to get the total time for the day.
(The reason I do not have a seperate record for each entry is because I have
to transfer the data to an IBM UniData Table)

When I use DatePart I get the result of a Calendar Day.

Does anyone know how to do this so I get Total Hours.

Example: TotalDay = DatePart("h", JobA) + DatePart("h", JobB)
Total Day End Up 12/30/1899 instead of 2.00 hours.

Thanks in Advance

Bill
 
D

Douglas J Steele

The Date data type is intended for timestamps (i.e. complete date and time),
not for durations.

The usual advice is to store durations as Long Integers, where 1 represents
whatever granularity you require (i.e.: 1 second, 1 minute, 1 hour, etc.)
 
J

John A.

Doug is right about the use of the fields with Date type - but you can have
a StartTime and a StopTime field, and then
do 24 * ([StopTime]-[StartTime]) to get the duration in hours.
John
 
D

Douglas J Steele

For that matter, his TotalDay field likely contains the information he
needs: Hour(TotalDay) or DatePart("h", TotalDay) will likely result in the
duration. Even if the duration is greater than 24 hours, it's possible to
retrieve it from the field. Check my October, 2003 "Access Answers" column
in Pinnacle Publication's "Smart Access" (You can download the column, and
accompanying sample database, for free at
http://www.accessmvp.com/DJSteele/SmartAccess.html)

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


John A. said:
Doug is right about the use of the fields with Date type - but you can have
a StartTime and a StopTime field, and then
do 24 * ([StopTime]-[StartTime]) to get the duration in hours.
John

Bill Barber said:
I have seven fields in a record to record hours. Each field is defined
as
a
Date/Time field with a Format of Short Date with the Mask of a short date.

I want to add these seven field together to get the total time for the day.
(The reason I do not have a seperate record for each entry is because I have
to transfer the data to an IBM UniData Table)

When I use DatePart I get the result of a Calendar Day.

Does anyone know how to do this so I get Total Hours.

Example: TotalDay = DatePart("h", JobA) + DatePart("h", JobB)
Total Day End Up 12/30/1899 instead of 2.00 hours.

Thanks in Advance

Bill
 
J

John A.

Doug -

As usual, a nice comprehensive look at the problem. Thanks for the
reference to your article

John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top