Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Comparing 1st and 2nd dates in a list Post Reply Post New Topic
Author Message
cloubuster
Newbie
Newbie
Avatar

Joined: 22 Aug 2008
Location: United States
Online Status: Offline
Posts: 2
Quote cloubuster Replybullet Topic: Comparing 1st and 2nd dates in a list
     Posted: 22 Aug 2008 at 8:40am

I have multiple dates in the Details section for each grouped item in my report. How can I do a formula that will give me the difference between the 1st and 2nd dates in the details section?

Example: 1st date - 5/5/08
                2nd date - 5/7/08
                3rd date - 5/11/08
 
The difference should be 2 (5/5 to 5/7). Can this be done? Where in the report should I place this info once i have it?
 
IP IP Logged
neinta
Newbie
Newbie


Joined: 26 Aug 2008
Location: United States
Online Status: Offline
Posts: 6
Quote neinta Replybullet Posted: 26 Aug 2008 at 6:40am
DATEDIFF("d", PREVIOUS({Date}), {date}) // {date} is your date field

This will give you the difference between the date and the one above it.  You have to put the formula in the details section.




IP IP Logged
cloubuster
Newbie
Newbie
Avatar

Joined: 22 Aug 2008
Location: United States
Online Status: Offline
Posts: 2
Quote cloubuster Replybullet Posted: 26 Aug 2008 at 2:34pm
Cool...now, is there any way I can do this in the group footer section? So it'll just do the difference between the 1st and 2nd dates in the details section?
IP IP Logged
neinta
Newbie
Newbie


Joined: 26 Aug 2008
Location: United States
Online Status: Offline
Posts: 6
Quote neinta Replybullet Posted: 26 Aug 2008 at 3:46pm
Create a running total:

RTotal0 -
    Count the date
    Evaluate for every record
    Reset for each group

Create a few formulas:

In Details -
RECORD2 - Runs datediff only on the second record.  (Can be suppressed)
    if {#RTotal0} = 2 then {@DateDiff}

In the group header - 
VAR_RESET - Resets the Variable to 0 for each group. (Can be Suppressed)
    shared numbervar X := 0;

In the Group Footer -
VAR_DEC - Declares the Variable and returns the value for the second record
    shared numbervar X ;
    if {@RECORD2} > 0  then X := {@RECORD2};
    X

If this doesn't work, let me know ( it worked for me)


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