Calculate last 3 years dynamically

I have a field that contains dates in the format YYYYMMDD (4-digit year, 2-digit month, 2-digit day). I want to read records where date is within the past 3 years from today’s date.

For example, today is 2023-08-31. So I want to read records where date is between 20200101 and 20230831, inclusive. This will return records from 2020, 2021, 2022, and up to today in 2023.

Hello Yaniv,

I am not sure what is your challenge to perform the calculation, please see our code sample project on GitHub you might find your answer on this sample.

Eli

DEFINE DATA LOCAL
1 FILE1 VIEW OF SOME-FILE
1 #THREE-YEARS-AGO-YYYY     (A4)
1 REDEFINE #THREE-YEARS-AGO-YYYY
  2 N       (N4)
1 #TODAY-YYYYMMDD (A8)
END-DEFINE
*
MOVE EDITED *DATX TO #THREE-YEARS-AGO-YYYY (EM=YYYY)
SUBTRACT 3 FROM #THREE-YEARS-AGO-YYYY.N
*
READ FILE1 FROM #THREE-YEARS-AGO-YYYY TO #TODAY-YYYYMMDD
...etc...

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.