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

Summary on Time formula. help 1

Status
Not open for further replies.

ipazzo

Programmer
Jan 17, 2002
69
IT
Hi experts,
i have this formula on a detail row

Code:
WhilePrintingRecords;
NumberVar SecondsDiff := DateDiff("s", {trv.hbegin}, {trv.hend} );
NumberVar Hours;
NumberVar Mins;
NumberVar Secs;
SecondsDiff := IIF (SecondsDiff > 0, SecondsDiff, 0 );
Hours := truncate(secondsdiff/3600);
Mins := truncate(((SecondsDiff/3600) - Hours)*60);
Secs := truncate(((((SecondsDiff/3600) - Hours)*60) - Mins)*60);

Time(Hours,Mins,Secs);

The question is ...

...

how can i have summary information in group footer for that formula ? If i rightclick the formula i don't have the option to insert summary.

I have CR 9.2

Thanks in advance for any suggestion.



Vito M. from BARI (Italy)
---------------------------------------
When you build a TEAM, try always those that they love to win. If you do not succeed to find them, then try those that they hate to lose. Ross Perot
 
Create a separate formula for the timediff {@timediff}:

DateDiff("s", {trv.hbegin}, {trv.hend})

Then create another formula for the summary:

WhilePrintingRecords;
NumberVar SecondsDiff := sum({@timediff},{table.groupfield});
NumberVar Hours;
NumberVar Mins;
NumberVar Secs;
SecondsDiff := IIF (SecondsDiff > 0, SecondsDiff, 0 );
Hours := truncate(secondsdiff/3600);
Mins := truncate(((SecondsDiff/3600) - Hours)*60);
Secs := truncate(((((SecondsDiff/3600) - Hours)*60) - Mins)*60);

Time(Hours,Mins,Secs);

You might have to add in a variable for Day if the result exceeds 23 hours.

-LB
 
Hi lbass,

thanks for your solution, works fine except for the case where DateDiff is used over two records.
Code:
----------
@cicleDiff
DateDiff("s", {trv.hbegin}, next({trv.hbegin}))

---------
@cicleAvg
WhilePrintingRecords;
NumberVar SecondsDiff := average({@cicleDiff},{table.groupfield});
NumberVar Hours;
NumberVar Mins;
NumberVar Secs;
SecondsDiff := IIF (SecondsDiff > 0, SecondsDiff, 0 );
Hours := truncate(secondsdiff/3600);
Mins := truncate(((SecondsDiff/3600) - Hours)*60);
Secs := truncate(((((SecondsDiff/3600) - Hours)*60) - Mins)*60);

Time(Hours,Mins,Secs);

do you have any suggestion for this case ??



Vito M. from BARI (Italy)
---------------------------------------
When you build a TEAM, try always those that they love to win. If you do not succeed to find them, then try those that they hate to lose. Ross Perot
 
Create four formulas:

//{@reset} to be placed in the group header:
whileprintingrecords;
numbervar sumtime := 0;
numbervar counttime := 0;

//{@timediff}:
if {table.groupfield} = next({table.groupfield}) then
DateDiff("s", {trv.hbegin}, next({trv.hbegin})) else 0

//{@average} to be placed in the details section and suppressed:
WhilePrintingRecords;
numbervar sumtime := sumtime + {@timediff};
numbervar counttime := counttime + 1;
numbervar ave;

if counttime > 1 then
ave := sumtime/(counttime-1) else
ave := 0;

//{@display} to be placed in the group footer:
WhilePrintingRecords;
NumberVar ave;
NumberVar Hours;
NumberVar Mins;
NumberVar Secs;
SecondsDiff := IIF (ave > 0, ave, 0 );
Hours := truncate(ave/3600);
Mins := truncate(((ave/3600) - Hours)*60);
Secs := truncate(((((ave/3600) - Hours)*60) - Mins)*60);

Time(Hours,Mins,Secs);

-LB
 
GRANDEEEEE :D
This works ;) ... a star for you
Tanks again.


Vito M. from BARI (Italy)
---------------------------------------
When you build a TEAM, try always those that they love to win. If you do not succeed to find them, then try those that they hate to lose. Ross Perot
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top