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
hamlin11Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
DB Reporting Tools

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.