Kbase P145085: 4GL/ABL: Wrong value returned by the INTERVAL function
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  08/01/2010 |
|
Status: Unverified
SYMPTOM(s):
4GL/ABL: Wrong value returned by the INTERVAL function
Executing the following MESSAGE statement, INTERVAL (4/30/2009,3/31/2009,"MONTHS") returns 0 and NOT the expected value of 1:
MESSAGE INTERVAL (4/30/2009,3/31/2009,"MONTHS")
VIEW-AS ALERT-BOX.
FACT(s) (Environment):
All Supported Operating Systems
OpenEdge 10.1x
OpenEdge 10.2A
CAUSE:
Bug# OE00183606
CAUSE:
The INTERVAL function is not "end-of-month aware". The current logic has no specific handling for end-of-month: if the day of the later date is before the day of the earlier date, it is assumed that a whole month has not passed. For example: INTERVAL (4/30/2009,3/31/2009,"MONTHS") returns 0.
FIX:
The INTERVAL function currently works as designed. The following ABL monthInterval user-defined function, UDF, will provide an end-of-month aware MONTH interval between two dates. The logic is that if the day of the first date is less than the day of the second date and both dates are end-of-months,then add a month.
It is up to the developer to decide how to address situations where the first date is an end-of-month and the second date is not. For example, according to this UDF, the interval between 02/28/2009 and 01/31/2009 is one month, but is the interval between 02/28/2009 and 01/29/2009 also a month?
FUNCTION monthInterval RETURNS INTEGER(INPUT ddate1 AS DATE, INPUT ddate2 AS DATE):
DEFINE VARIABLE imonths AS INTEGER NO-UNDO.
imonths = INTERVAL(ddate1,ddate2,"MONTHS").
/* handle possible end-of-month situations */
IF (DAY(ddate1) < DAY(ddate2)) THEN
DO:
/* check if ddate1 is an end-of-month and ddate2 is end-of-month */
IF (MONTH(ddate1 + 1) > MONTH(ddate1)) AND
(MONTH(ddate2 + 1) > MONTH(ddate2)) THEN
imonths = imonths + 1.
END.
RETURN imonths.
END.
MESSAGE monthInterval(4/30/2009,3/30/2009)
VIEW-AS ALERT-BOX INFO BUTTONS OK.