Average Time between records
I have a field 'recordDateTime' in my DB table. On a report's summary
band, I would like to show a value "average time between postings".
For example, if my DB had the following records:
recordDateTime
--------------
9/2/2001 4:00:00 pm
9/2/2001 4:10:00 pm
9/2/2001 4:20:00 pm
I would like the summary band to be able to read "10 minutes", although
it doesn't matter what format (I'd be willing to do conversion via
code.) It doesn't look like I can use a DBCalc component.
Can anyone help?
Thanks.
band, I would like to show a value "average time between postings".
For example, if my DB had the following records:
recordDateTime
--------------
9/2/2001 4:00:00 pm
9/2/2001 4:10:00 pm
9/2/2001 4:20:00 pm
I would like the summary band to be able to read "10 minutes", although
it doesn't matter what format (I'd be willing to do conversion via
code.) It doesn't look like I can use a DBCalc component.
Can anyone help?
Thanks.
This discussion has been closed.
Comments
try something like:
For the report use a query which sorts on your posting date.
Create a TList (MeanList) with the report.
Define a TObject (Timepart) which contains two doubles.
Use a ppVariable to show the date. Within the onCalc event of the
ppVariable create a new TObject (Timepart), set the first double with
the current datetime and put the TObject into the TList (MeanList).
Within the beforegenerate event of the summary band compute your mean.
Get the first datetime. Store it into a variable. Set the second double
to zero.
Go to the next list item. Subtract the variable from the current
datetime. Store the result into the second double. Store current
datetime to variable.
Repeat till list end.
Build summary of all second datetimes (Beware a datetime integral part
are the days and the fraction shows the hours, minutes and seconds of a
day. Therefore build a sum of minutes: integral part * 1440 and add the
hours * 60 and minutes you got by a DecodeTime(,,,,)).
Divide sum by Listcount.
Mean done.
Show the mean via a ppLabel.
Free the TObjects within the TList.
Free the TList.
enjoy,
Ron.