Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Date formula issue Post Reply Post New Topic
Author Message
Jock
Newbie
Newbie
Avatar

Joined: 29 Mar 2012
Location: United Kingdom
Online Status: Offline
Posts: 6
Quote Jock Replybullet Topic: Date formula issue
     Posted: 02 Apr 2012 at 3:11am
Hi,
Crystal is querying a data source (Access table).
One of the fields is {session.session date}.
For each data set, this field will have a minimum of one date entry but will have no upper limit although 9 is probably going to be the max.
What I need to do is work out is:
  • how many dates are in this field per data set, and from that:
  • the date diff between the second to last date and the first one; and
  • the date diff between the last date and the second to last.

Some data sets will have only one date, some will have two but most will have three or more.

Is this possible?

Traa dy liooar
IP IP Logged
rkrowland
Senior Member
Senior Member
Avatar

Joined: 20 Dec 2011
Location: England
Online Status: Offline
Posts: 259
Quote rkrowland Replybullet Posted: 02 Apr 2012 at 4:35am
I haven't tried this, but I'm guessing it should work. Give it a try and have a play around and if you can't get something from it I'll have a closer look.
 
Order your records ascending by the date field.
 
Create 4 formulas;
 
Min
minimum({table.datefield})
 
Max
maximum({table.datefield})
 
Next
Next({table.datefield})
 
Prev
previous({table.datefield})
 
Now we're going to try and perform calculations based on the results of these formulae.
 
for the earliest to second to last calc (assuming you want difference in days);
 
if {@next} = {@Max}
then datediff("d",{@Min},{table.datefield})
 
Now for the second to last to last difference;
 
if {table.datefield} = {@Max}
then datediff("d",{@Prev},{table.datefield}
 
Let me know how you get on as I'm not the most experienced person with the next/prev functions.
 
Regards,
Ryan.
 
[EDIT]
You may need to throw some is null checks in there for the records without a date entry.
 


Edited by rkrowland - 02 Apr 2012 at 4:43am
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