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


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?

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.

what is your code?
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

Open in new window

hamlin11Author Commented:
I think I'm doing my date comparisons wrong... any tips?
Exploring ASP.NET Core: Fundamentals

Learn to build web apps and services, IoT apps, and mobile backends by covering the fundamentals of ASP.NET Core and  exploring the core foundations for app libraries.


use like this

IF (({?D1} >= StartDate) AND ({?D1} <= EndDate)) THEN
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.


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
Hmm.  I don't know.  It sounds odd.  IAC, I'm glad you got it working.

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.