• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 563
  • Last Modified:

Crystal Reports - Formula - Display a value if a Date is between a Start Date and an End Date

Greetings,

Please see the code snippet below.

I want to display a SalesAmount value when the MyDate value is between StartDate and EndDate.

The reason I define start date and end date in the code is for testing - eventually I'll setup some input paremeters for users of the report.

This code ALWAYS includes the SalesAmount and never outputs 0 -- even for results from the year 2003

A) Is there a bug in my code?

B) Is there some simple way to debug formulas without having to run the whole report?

Thanks
0
hamlin11
Asked:
hamlin11
  • 3
  • 2
  • 2
2 Solutions
 
tigin44Commented:
what is your code?
0
 
hamlin11Author Commented:
Sorry I forgot to paste the code..



DateVar D1 = {SomeTable.MyDate};
DateVar EndDate = Date(2008, 9, 1);
DateVar StartDate = Date(2008, 8, 1);
 
IF ((D1 >= StartDate) AND (D1 <= EndDate)) THEN
    {someTable.SalesAmount}
ELSE
   0

Open in new window

0
 
hamlin11Author Commented:
I think I'm doing my date comparisons wrong... any tips?
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
tigin44Commented:


use like this

IF (({?D1} >= StartDate) AND ({?D1} <= EndDate)) THEN
    {someTable.SalesAmount}
ELSE
0
 
James0628Commented:
The only thing I really see is that in your variable declarations, you have =.  It should be :=.  Otherwise, the code seems reasonable.

 D1 seems pointless (you could just use the field), but it should work.

 As for debugging, it depends on your report.  You could temporarily do something to restrict the report so that it only reads a few records (change parameters, add record selection conditions, etc.).  With a simple formula like this, you could copy it to a blank report, stick it in the report header, replace {SomeTable.MyDate} with a parameter, and just refresh the report and try different values, etc.

 James
0
 
hamlin11Author Commented:
I don't know what the deal is, but i wouldn't work even after I switched "=" to ":="

However, It eventually started working. I don't know what the deal is, but maybe I had to refresh the report.

Thanks for your help
0
 
James0628Commented:
Hmm.  I don't know.  It sounds odd.  IAC, I'm glad you got it working.

 James
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now