Hey,
Why is there a difference in usesage of a + or a - with a date context?
For example:
define variable l-date as date no-undo.
l-date = today + 1.
=> 28/02/17 = >ok
l-date = 1 + today.
=> 28/02/17 => ok
l-date = today - 1
=> 26/02/17 =>ok
l-date = 1 - today
=> nok
---------------------------
Error (Press HELP to view stack trace)
---------------------------
** Incompatible data types in expression or assignment. (223)
** Could not understand line 3. (196)
---------------------------
OK Help
---------------------------
Lien,
What would be the desired result of the expression that fails?
The same result als today - 1.
Which normally dosn't matter in progress which order the expression is displayed except when you use brackets
- See more at: community.progress.com/.../100289
You can't expect a date to become negative
Rather then using +1 and -1 , use the add-interval
The order of the operands does not matter for + and *, but it does for - and /.
10 + 1 = 11
1 + 10 = 11
10 - 1 = 9
1 - 10 = -9
l-date = today - 1 is equivalent to l-date = DATE(2457813 - 1)
l-date = 1 - today is equivalent to l-date = DATE(1 - 2457813)
So the first one returns DATE(2457812), which is 26 February 2017 AD.
The second one returns DATE( -2457812 ), which is 16 November 11443 BC.
The fact that the "1 - today" doesn't work probably should be reported as a Tech Support case.
There's 2 implicit data type conversions here: from date to integer to resolve the expression, and then back from integer to date for the variable assignment.
If the other variants support the implicit data type conversions to make this work, there's no reason this one shouldn't so this can be considered a defect.
I'll second gdb390's suggestion to use add-interval for any time-based calculations though.
That keeps the intent clearer in my eyes.
Wouldn't 1 - TODAY result in an integer value (the number of days between DATE(1) and today)? If so, the error is correct because you're trying to put an integer result into a date variable.
Though 1 - today could (should?) be valid, I can't imagine myself intentionally writing such an expression. If I wrote 1 - today, I'd be glad the compiler told me about my probable mistake.
How about TODAY - TODAY vs. TODAY + TODAY? Which should compile, which shouldn't and why?