I would consider a Case instead of nested If. A little easier to troubleshoot and I hear they are faster as well.
I agree with bigtom - a Case statement is easier to read than a nested If.
However, in your case, I think you can still use an If statement to determine if the project is taking place today:
Get ( CurrentDate ) >= TABLE::dateStart and
Get ( CurrentDate ) <= TABLE::dateEnd ;
That's weird. I was able to get your exact statement to work. Can you give us an example of when it fails? Every time?
Here's my statement to solve the question "Is this product running today?":
_Date = Get(CurrentDate);
_Start = Order Start Date;
_End = End Date
_Date ≥ _Start and _Date ≤ _End ;
//If today's date is greater that the start date and less than the end date
// True: return a 1
// False: return a 0
Thank you all for the responses. I will work with the case statement, if for nothing else, the new experience.
However, I found my original problem.
When using StartDate > CurrentDate, I did not change the equation for tomorrow or the next day,
so the StartDate was always greater than today (at least for today) in each of my equations.
So I needed to change tomorrow to StartDate > CurrentDate+1 and so on..... +2, +3....
Case statements are meant for testing a whole bunch of possibilities.
_Today = DayName (Get (CurrentDate));
_Today = "Monday"; "ugh, another week is starting!";
_Today = "Tuesday" ; "It's only Tuesday?";
_Today = "Wednesday" ; "Hump day!"
_Today = "Thursday" ; "Almost Friday, almost Friday";
_Today = "Friday"; "YES! The weekend!"; ""
You have one possibility: Is today's date greater than the start date AND is it less than the end date. You case statement would look exactly like the if statement.
Please try case statements. What's cool about them is that they stop at the first true statement, so you want to put the most likely outcome (if applicable) at the beginning so they stop calculating faster. But I am sure the difference is just a fraction of a millisecond.
I would strongly suggest you set this up as a Let() because:
1. It is much easier to set out clearly the logic of your argument
2. It is more efficient because you can remove multiple DB calls—your original If() calc calls StartDate and EndDate twice each, and Get ( Current Date ) four times, so set them up as variables, thus calling each once only, then reference the variables in a Case() in the result portion of the Let() calc.
Thanks keywords, I forgot to explain why I set it up in Let statements.