Calculating 6 months backwards from todays date

Charter

New Member
Hi,

A report needs to run every 6 months in the past from todays date.
So were in Month 09 (sept) so If I ran the report today i should get the output for the last 6 months
02 04 05 06 07 08.

and then i would like it to be displayed in my temp-table

The code I am is caclulating the future - how can i calculate the past?

DEFINE VARIABLE daDate AS DATE NO-UNDO.
DEFINE VARIABLE iLoop AS INTEGER NO-UNDO.
DEFINE VARIABLE chDateRange AS CHARACTER NO-UNDO.
ASSIGN
daDate = DATE(TODAY).
DO iLoop = 1 TO (1 * 6):
chDateRange = chDateRange + STRING( ADD-INTERVAL(daDate,iLoop,'months'),'99/99/9999') + ' '.
END.

ASSIGN (TEMP TABLE)
 

Stefan

Well-Known Member
Use - iloop?

Code:
DEFINE VARIABLE daDate AS DATE NO-UNDO.
DEFINE VARIABLE iLoop AS INTEGER NO-UNDO.
DEFINE VARIABLE chDateRange AS CHARACTER NO-UNDO.
ASSIGN
daDate = DATE(TODAY).
DO iLoop = 1 TO (1 * 6):
   chDateRange = chDateRange + STRING( ADD-INTERVAL( daDate, - iLoop, 'months':U ), '99/99/9999' ) + ' '.
END.
MESSAGE chDateRange VIEW-AS ALERT-BOX.
 

Charter

New Member
Thanks Stefan! I didn't think of using minus iLoop!
However my only concern is that I want the output to be placed inside a temp table tt-report in the turnover field. so i get the output something like:

Apr 11 May 11 June 11 Jul 11 Aug 11 Sept 11
£13923 £15463 £43743 £5653 £56431 £65131

I look forward to reading your response...

Thanks
 

rzr

Member
Code:
DEFINE VARIABLE daDate AS DATE    NO-UNDO.
DEFINE VARIABLE iLoop  AS INTEGER NO-UNDO.

DEFINE TEMP-TABLE tt-report 
       FIELD t_Date     AS DATE
       FIELD t_TurnOver AS INTEGER.

ASSIGN daDate = DATE(TODAY).

DO iLoop = 1 TO (1 * 6):

   CREATE tt-report.
   ASSIGN
       t_Date     = ADD-INTERVAL( daDate, - iLoop, 'months':U )
       t_TurnOver = 10 * iLoop /*Some Junk Value*/
        .
END.

FOR EACH tt-report :
    DISPLAY tt-report.
END.
 
Top