Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: Duration formula Post Reply Post New Topic
Author Message
nhopp4
Groupie
Groupie


Joined: 03 Oct 2012
Location: United States
Online Status: Offline
Posts: 62
Quote nhopp4 Replybullet Topic: Duration formula
     Posted: 04 Oct 2012 at 2:33am
Hi experts!  I am a newbie on Crystal Reports and our business just started using crystal reports and I have been thrown in learning on my own.  I am trying to do a duration formula.  However, the fields that I have are Report_Events.Timestamp (Date Time that event starts and stops).  Also, I have Reports_Events.Type (Has the data "Start", "Stop".  So I need to create a report for the stop datetime - start datetime duration in seconds but can I do this with there not being a StartTimestamp and a StopTimestamp?
 
Thanks in advance.. Any help would be appreaciated!
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 04 Oct 2012 at 3:05am

If you order the data by the Timestamp will there always be a corresponding Stop for every Start and Start for every Stop?

-Dell
IP IP Logged
nhopp4
Groupie
Groupie


Joined: 03 Oct 2012
Location: United States
Online Status: Offline
Posts: 62
Quote nhopp4 Replybullet Posted: 04 Oct 2012 at 3:46am
Yes I sorted by timestamp and there is a corresponding start for every stop and a stop for every start.
My report looks like this:
Name         Timestamp                      Type
'Palette'      10/4/2012 8:45 am        'Start'
'Palette'      10/4/2012 8:50 am        'Stop'
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 04 Oct 2012 at 4:05am
Try this:
 
1.  Create a formula to contain the start time (I'll call this {@StartTime}):
 
DateTimeVar startTime;
if {MyTable.Type} = 'Start' then startTime := {MyTable.Timestamp};
startTime
 
2.  Create a second formula called Duration (this one does minutes):
 
if {MyTable.Type} = 'Stop' then DateDiff('n', {@StartTime}, {MyTable.TimeStamp})
 
Use this formula on your report.
 
-Dell
 
IP IP Logged
nhopp4
Groupie
Groupie


Joined: 03 Oct 2012
Location: United States
Online Status: Offline
Posts: 62
Quote nhopp4 Replybullet Posted: 04 Oct 2012 at 5:03am
Those formulas worked great!  Another question the duration formula shows a 0 for the stop time and shows the duration on the stop time.  How do I make it so it will just show the duration on the stop time?
IP IP Logged
nhopp4
Groupie
Groupie


Joined: 03 Oct 2012
Location: United States
Online Status: Offline
Posts: 62
Quote nhopp4 Replybullet Posted: 04 Oct 2012 at 5:04am
Correction shows a 0 for the start time.
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 04 Oct 2012 at 6:00am

Right-click on the duration object in the report and select "Format...".  Go to the first tab and click on the button to the right of "Suppress" (DO NOT check the checkbox!) and enter something like the following:

{MyTable.Type} = 'Start'
 
This should suppress the duration on the start record.
 
-Dell
IP IP Logged
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum