average calculation for Pages Per Hour

Faction21

Registered User.
Local time
Today, 17:39
Joined
Oct 26, 2004
Messages
42
how do you get an average of pages per hour for this?

Average PPH: Int(Sum([EndTime]-[StartTime]))*24+DatePart("h",Sum([EndTime]-[StartTime])) & " hr " & Format(Sum([EndTime]-[StartTime]),"n"" min ""s"" sec""")


Any help?

-thanks
 
I got it it kinda goes like this. So far it works for less than 24 hours, but is it possible for more than 24?

AveragePPH: Format(Sum([pagecount])/(Sum(DateDiff("h",[StartTime],[EndTime]))),"#")
 
Last edited:
Your start and end fields need to include the date. Date/time fields are not well understood. They are not strings, they are double precision numbers and they are intended to hold a point in time. That point is a date and the exact time of day. You may choose to store only the date portion or only the time portion but if you need to do arithmetic with the value, I strongly suggest that you use the field as it is intended. You can acutally add the date field and the time field if they are currently separate.

AveragePPH: Format(Sum([pagecount])/(Sum(DateDiff("h",[StartDate] +[StartTime], [EndDate] + [EndTime]))),"#")
 
DateDiff("h", [StartTime], [EndTime]) can't return the correct time in hours.

For example, DateDiff("h",#12/26/2004 8:58:0#,#12/26/2004 9:0:0#) will return 1 hour (i.e. 9 - 8) though actually only two minutes has elapsed.

The correct expression to use is ([EndTime]-[StartTime])*24 as [EndTime]-[StartTime] remains a date/time value and the unit of a date/time value is day and each day has 24 hours.


As an illustration, I have attached a sample database with a table "tblData" :
Code:
[b]ID	PageCount	     StartTime		       EndTime[/b]
001	  60		     8:00:00 AM		     9:00:00 AM
001	  30		     8:30:00 AM		     9:00:00 AM
002	  61		     8:00:00 AM		     9:01:00 AM
002	  33.5		     8:30:00 AM		     9:03:30 AM
003	  61	 26/12/2004 11:30:00 PM	 27/12/2004 12:31:00 AM
003	1473.5	 26/12/2004  8:30:00 AM	 27/12/2004  9:03:30 AM
004	3000	 26/12/2004  8:30:00 AM	 28/12/2004  9:23:26 AM
and two queries :

"Pages per hour"
SELECT ID, PageCount, StartTime, EndTime,
Int([EndTime]-[StartTime])*24+DatePart("h",[EndTime]-[StartTime]) & " hr " & Format([EndTime]-[StartTime],"n"" min ""s"" sec""") AS [Time],
Round(([EndTime]-[StartTime])*24,4) AS [Total Hours],
Round([PageCount]/[Total Hours],2) AS [Pages Per Hour]
FROM tblData;

"Average Pages per hour"
SELECT [ID], Sum([PageCount]) AS [Page Count],
Int(Sum([EndTime]-[StartTime]))*24+DatePart("h",Sum([EndTime]-[StartTime])) & " hr " & Format(Sum([EndTime]-[StartTime]),"n"" min ""s"" sec""") AS [Total Time],
Round(Sum([EndTime]-[StartTime])*24,4) AS [Total Hours],
Round([Page Count]/[Total Hours],2) AS [Average Pages Per Hour]
FROM tblData
GROUP BY [ID];


When the queries are run, they will return the results :
Code:
[b]ID   PageCount  StartTime  EndTime   Time	          Total       Pages 
							  Hours     Per Hour[/b]
001      60	......	   ......    1 hr  0 min  0 sec	   1          60
001      30	......	   ......    0 hr 30 min  0 sec	   0.5        60
002      61	......	   ......    1 hr  1 min  0 sec	   1.0167     60
002      33.5	......	   ......    0 hr 33 min 30 sec	   0.5583     60
003      61	......	   ......    1 hr  1 min  0 sec	   1.0167     60
003    1473.5	......	   ......   24 hr 33 min 30 sec	  24.5583     60
004    3000	......	   ......   48 hr 53 min 26 sec	  48.8906     61.36


[b]ID	Page Count	Total Time		Total Hours	Average Pages
								   Per Hour[/b]
001	  90		 1 hr 30 min  0 sec	 1.5		      60
002	  94.5		 1 hr 34 min 30 sec	 1.575		      60
003	1534.5		25 hr 34 min 30 sec	25.575		      60
004	3000		48 hr 53 min 26 sec	48.8906		      61.36


Note: If the EndTime crosses mid-night, the dates must also be entered in the two time fields (as shown in the last three records in the table.)

If the dates are stored in two separate fields in the table, you can use the following expression to return the time in Hours:-
(([EndDate]+[EndTime]) - ([StartDate]+[StartTime]))*24
.
 

Attachments

Last edited:
Oh wow, what did i get into, lol. Thanks a whole bunch man im going to look into the database. :)
 
What if the Time is less than one hour? Im getting a ERROR "Cannont Divide By Zero" now that im testing data.

*EDIT*
I will repost the line that is giving me touble in a few...

It is because I'm returning the value in hour, but if its less than 1 hour, it get the error.

How can i fix this?
 
Last edited:
I don't think time less than one hour would be the problem. Jon's sample contained two records with time less than one hour.

It would divide by zero only if the StartTime and EndTime are the same.

~
 
Last edited:

Users who are viewing this thread

Back
Top Bottom