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

Joined: 08 Jul 2010
Online Status: Offline
Posts: 24
Quote bluelake Replybullet Topic: Date formula
     Posted: 06 Jun 2012 at 11:20am
I'm trying to write a formula to compare two date fields.  Date field A will be updated periodically, so there will be several records in the field.  I want to see if Date B is in the range of the current Date A.  BTW, this is in a subreport.

Example: 

Date A:  1/1/12
              3/1/12
              5/6/12

Date B is 2/14/12 so I only want to compare it to the data for the data that was current at the time, Date A = 1/1/12

If Date B was 4/15/12, then it would compare to Date A = 3/1/12 because it was the most current data at that time.

Any help is appreciated.


IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 07 Jun 2012 at 12:04pm
My first response is always...use a stored proc, life is much simpler there.
 
If that is not an option, this the idea that I would pursue ( I haven't needed this so I haven't done it and might get things wrong).
 
I would create a group in the subreport based on dateA, descending  (5/6/12, 3/1/12, 1/1/12). Then I would do a top n report with n = 1. I would apply a filter that dateA <= dateB.
 
These 3 things combined should give the correct date that you are after.
 
Hopefully this points you in a direction
IP IP Logged
bluelake
Newbie
Newbie
Avatar

Joined: 08 Jul 2010
Online Status: Offline
Posts: 24
Quote bluelake Replybullet Posted: 08 Jun 2012 at 4:34am
lockwelle, Thank you for your response.  I'm not only a newbie to CR, but programming in general.  I don't know what a stored proc is.  I also don't understand what you mean by "top n report."  What I have done is group the data in the subreport by Date A.  I've written a formula:

if {Date B} >={Date A} then true else false

This works in looking at the most current date.  The problem now is, that it shows all dates that are greater than {Date A} in the detail section. Example, if Date B is 4/16/12, it shows in the detail section for the first and second groups.  I only want it to display dates that are >= the group header, but < the next group header.

I've tried {Date B} <(next{Date A}) then true, but it sees  the next value as the group header, not the true next value.  I've also tried maximum with the same results.



IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 08 Jun 2012 at 4:53am
a stored proc is a list of sql commands to be executed. The result of which can be used by Crystal Reports.
 
There is a style of report that is the top n entries. I am not too sure how to go about it as I haven't had a need of one. I am sure that if you look for 'top n' in the forum you will find several entries. I know that DBlank has answered several posts about them.
 
CR help is also a good resource...perhaps not the best, but that is where I learned most of what I know about CR.
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