jwebster77
asked on
Calculate time for records in a crystal report
I have a crystal report, develop in VB. In the details section you would see rows of records like the following.
TIme In 2:00 AM Time Out 3:00 AM Elapsed 0.00
Time In 3:05 AM Time Out 4:00 AM Elapsed 5 minutes
etc.
I want to calculate the elapsed time between the current record and the one sitting above it. Records will be sorted by time out
TIme In 2:00 AM Time Out 3:00 AM Elapsed 0.00
Time In 3:05 AM Time Out 4:00 AM Elapsed 5 minutes
etc.
I want to calculate the elapsed time between the current record and the one sitting above it. Records will be sorted by time out
ASKER
Hi there, I tried the below.
WhilePrintingRecords;
Local NumberVar ElapsedSeconds;
If OnFirstRecord Then
ElapsedSeconds := 0
Else
ElapsedSeconds := DateDiff('m', Previous({tblLabor.TimeOut }), {tblLabor.TimeIn});
'Elapsed ' & CStr(ElapsedSeconds,'0') & ' minutes'
The results are attached. You will see where it did not evaluate and still shows zero.
idletimeexample.JPG
WhilePrintingRecords;
Local NumberVar ElapsedSeconds;
If OnFirstRecord Then
ElapsedSeconds := 0
Else
ElapsedSeconds := DateDiff('m', Previous({tblLabor.TimeOut
'Elapsed ' & CStr(ElapsedSeconds,'0') & ' minutes'
The results are attached. You will see where it did not evaluate and still shows zero.
idletimeexample.JPG
ASKER
mlmcc any thoughts? Thanks!
Try this just to see what it thinks the previous time is
CHange your formula to
CHange your formula to
WhilePrintingRecords;
Local NumberVar ElapsedSeconds;
If OnFirstRecord Then
"First Record"
Else
CStr( Previous({tblLabor.TimeOut})
ASKER
See attached. I may also need to have the first record recognize for each employee now that I think of it.
ASKER
file attached.
cr-example.JPG
cr-example.JPG
Here you go. The problem with the previous formula is m is for months. you have to use n for minutes.
If you need to total for each employee it will take 3 formulas
In the report header and group header add a formula
Name - DeclareVariables
Modify the one in the detail section
IN the group footer add a formula
Name - PrintTotalMinutes
mlmcc
WhilePrintingRecords;
Local NumberVar ElapsedMinutes;
If OnFirstRecord OR (Previous({EmployeeID Field}) <> {EmployeeID Field}) Then
ElapsedMinutes := 0
Else
ElapsedMinutes := DateDiff('n', Previous({tblLabor.TimeOut}), {tblLabor.TimeIn});
'Elapsed ' & CStr(ElapsedMinutes,'0') & ' minutes'
If you need to total for each employee it will take 3 formulas
In the report header and group header add a formula
Name - DeclareVariables
WhilePrintingRecords;
Global NumberVar TotalMinutes;
TotalMinutes := 0;
''
Modify the one in the detail section
WhilePrintingRecords;
Local NumberVar ElapsedMinutes;
Global NumberVar TotalMinutes;
If OnFirstRecord OR (Previous({EmployeeID Field}) <> {EmployeeID Field}) Then
ElapsedMinutes := 0
Else
ElapsedMinutes := DateDiff('n', Previous({tblLabor.TimeOut}), {tblLabor.TimeIn});
TotalMinutes := TotalMinutes + ElapsedMinutes;
'Elapsed ' & CStr(ElapsedMinutes,'0') & ' minutes'
IN the group footer add a formula
Name - PrintTotalMinutes
WhilePrintingRecords;
Global NumberVar TotalMinutes;
TotalMinutes
mlmcc
This question needs an answer!
Become an EE member today
7 DAY FREE TRIALMembers can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Open in new window
mlmcc