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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Converting a Calculated Time to Decimal

Status
Not open for further replies.
Jul 1, 2008
16
0
0
US
I have a calculated "WorkHours" in my time application. In an effort to create a Productivity measure, I need to divide this time into a single integer.

(ie, WorkHours = 2:15, CompletedTasks = 20; CompletedTasks/WorkHours=20/2.25=8.89 audits per hour
 
You should be storing time durations as numerics rather than as a date/time which are used to store a point in time. To get a number of hours from a time, multiply by 24. So
20/(24 * 2:15) = 8.89

Duane
Hook'D on Access
MS Access MVP
 
I tried multiplying the "WorkHours" by 24 and my query returns a column full of "#Error"s. This is my last roadblock.
 
WorkHours is a computed field but comoputed from a date/time field.

This query computes my time difference from a function:
SELECT qryLogData.RealDate, qryLogData.ActualTime, qryLogData.ID, qryLogData.emp_name, NextRec([ActualTime]) AS LogOutTime, Format([LogOutTime]-[actualtime],"Short Time") AS TimeDiff
FROM qryLogData
WHERE (((qryLogData.status)=1))
ORDER BY qryLogData.RealDate, qryLogData.ActualTime;

This query takes that info in prep for my report and formats:
SELECT id, emp_name, realdate, Format(Sum(CDate(TimeDiff)),"Short Time") AS WorkHours
FROM CalculateTimeDiff
GROUP BY id, emp_name, realdate;

I tried to convert the time by multiplying by 24:
SELECT (WorkHours*24) AS ConvTime
FROM FormatCalTimeDiff;

So now I'm trying to compute the division of the time for productivity:
SELECT [rprt audit].auditorid, [rprt audit].date, count([rprt audit].[trailer number]) AS NOA, ([NOA])/([FormatCalTimediff].[WorkHours]) AS PROD
FROM [rprt audit], FormatCalTimeDiff
GROUP BY [rprt audit].auditorid, [rprt audit].date;
 
The format function returns a string ...

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Don't format your dates/times until you want to display them. When you use Format([LogOutTime]-[actualtime],"Short Time") and Format(Sum(CDate(TimeDiff)),"Short Time") you are converting a perfectly good date/time value into a string that loses a ton of functionality. It might look pretty but is basically non-functional (like Jessica Simpson ;-)).

Try
Code:
SELECT qryLogData.RealDate, qryLogData.ActualTime, qryLogData.ID, qryLogData.emp_name, NextRec([ActualTime]) AS LogOutTime, [LogOutTime]-[actualtime] AS TimeDiff
FROM qryLogData
WHERE (((qryLogData.status)=1))
ORDER BY qryLogData.RealDate, qryLogData.ActualTime;
Code:
SELECT id, emp_name, realdate, Sum(TimeDiff) AS WorkHours
FROM CalculateTimeDiff
GROUP BY id, emp_name, realdate;
Code:
SELECT (WorkHours*24) AS ConvTime
FROM FormatCalTimeDiff;


Duane
Hook'D on Access
MS Access MVP
 
A consequence of doing it the way you are (instead of the way Duane is showing you) is that your calculations are probably wrong.

If you had
[tt]tblTestDates
ftime ttime Elapsed

7:00:00 AM 5:00:00 PM 10:00
7:00:00 AM 5:00:00 PM 10:00
7:00:00 AM 5:00:00 PM 10:00
7:00:00 AM 5:00:00 PM 10:00
[/tt]
It all appears correct

and now you run
Code:
SELECT Format(SUM(cDate(Elapsed)),"Short Time") as Telapsed
FROM tblTestDates
You get
[tt]Query Result
Telapsed

16:00
[/tt]
The correct total is 40 hours ... not 16. The reason this happens is that a datetime field cannot hold a value of more than 24 hours without rolling over to the next day and you are ignoring the date part of the field
 
I was able to enter the first set of code and it returned everything and the TimeDiff field displayed as a decimal, but the second set of code gave me a data type mismatch error, So I could not even run the last query.
 
Yes, they actually do have values. I have it set up to save and add the record when a command button is clicked. In the event procedure of that button, it records the time
Code:
rst!ActualTime = Time()
that the button is pressed which is the person's login or logout time.
 
However there are probably records that are not complete. Does the following return any records?
Code:
SELECT 
FROM qryLogData
WHERE qryLogData.status=1 AND ([LogOutTime] Is Null OR [actualtime] Is Null);

Duane
Hook'D on Access
MS Access MVP
 
Hi lyonder2000,

What I think is, that the problem might be, that date values are stored as a decimal, and the integer is for days, and the points for a fraction of a day.
so if you want to get the different between few hours, you will always get a fraction (a decimal with 0.###).
aND then you should calculate it to real hour value.

Here is a link , where you can see some functions aNd good advise, it should probably help you to get your result.

hope it will help
Ja
 
 http://allenbrowne.com/casu-13.html

Hi lyonder2000 again,

I'm am curious to know, if and how you solved your problem,

Thanks, Ja
 
I think I've found that a procedure I created is formatting my time and therefore making it a string so multiplying times the result returns an ERROR. I am working on adjusting my procedure.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top