Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Date Question Post Reply Post New Topic
Author Message
tbaird
Newbie
Newbie


Joined: 01 Dec 2008
Location: United States
Online Status: Offline
Posts: 2
Quote tbaird Replybullet Topic: Date Question
     Posted: 01 Dec 2008 at 6:01am
I am currently using Crystal Reports XI and I am attempting to write a report based on the date of a clients next appointment.  The fields I am pulling in are date fields, however when I pull the field in it shows all of their upcoming appointments.  I am wondering if there is a formula that only pulls the date nearest to the current date?  Thank you.
 
tbaird
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 01 Dec 2008 at 6:35am
What you need, it sounds like is a filter on the data in the table.
 
Report/Selection Formulas/Record is the way to build the filter.
 
entering something like:
{fieldname} >= now   should accomplish what it sounds like you want.
 
Hopefully, this will help, or at least point you a direction that does.
 
IP IP Logged
tbaird
Newbie
Newbie


Joined: 01 Dec 2008
Location: United States
Online Status: Offline
Posts: 2
Quote tbaird Replybullet Posted: 01 Dec 2008 at 11:30am
Lockwelle Thank you for the reply.  I tried the formula and it pulls all of the future appointments.  I am needing a formula that pulls only the closest appointment.  I have been researching and have been unable to have any success in finding one.  Thanks.
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 01 Dec 2008 at 12:03pm

OK, the next thing that i would try would be to add a command (Database/Database Expert/Add Command) and I would put something in like

SELECT MIN(diff) AS minDiff From (SELECT ABS(DATEDIFF(d, now, apptDateField) FROM apptTable ) s
 
Then in the record criteria look for dates, use the output of the command to filter your appoints by looking for appt that differ from today by  minDiff.  If you are only looking for future records, you can put a where clause on the select or remove the abs...
 
The select will return the closest difference, in the past or for the future compared to now.  If you need a finer granularity (d stands for day, you could change this to hh-hour or n-minute
 
Hope this gives you some ideas of how to attack this.
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