# Calculate last 3 years dynamically

**URL:** <https://techcommunity.softwareag.com/t/calculate-last-3-years-dynamically/282736>\
**Category:** Forum\
**Tags:** Adabas-Natural, Adabas, Natural\
**Created:** [August 31, 2023, 6:02am UTC](https://techcommunity.softwareag.com/t/calculate-last-3-years-dynamically/282736 "2023-08-31T06:02:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yaniv\_Zisano](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/yaniv_zisano/32/17410_2.png) [@Yaniv\_Zisano](https://techcommunity.softwareag.com/u/Yaniv_Zisano)\
**Post date:** [August 31, 2023, 6:02am UTC](https://techcommunity.softwareag.com/t/calculate-last-3-years-dynamically/282736/1 "2023-08-31T06:02:54Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Eli\_Cohen1](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/eli_cohen1/32/39733_2.png) [@Eli\_Cohen1](https://techcommunity.softwareag.com/u/Eli_Cohen1)\
**Post date:** [August 31, 2023, 11:57am UTC](https://techcommunity.softwareag.com/t/calculate-last-3-years-dynamically/282736/2 "2023-08-31T11:57:30Z")

</div>

Hello Yaniv,

I am not sure what is your challenge to perform the calculation, please see our [code sample project on GitHub](https://github.com/SoftwareAG/adabas-natural-code-samples) you might find your answer on [this sample](https://github.com/SoftwareAG/adabas-natural-code-samples/tree/main/Date%20%26%20Time%20Calculations).

Eli

---

<div class="post-metadata">

**Author:** ![Jerome\_LeBlanc](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/jerome_leblanc/32/111_2.png) [@Jerome\_LeBlanc](https://techcommunity.softwareag.com/u/Jerome_LeBlanc)\
**Post date:** [August 31, 2023, 2:50pm UTC](https://techcommunity.softwareag.com/t/calculate-last-3-years-dynamically/282736/3 "2023-08-31T14:50:21Z")

</div>

```auto
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...

```

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/techcommunity/original/3X/c/d/cd19967bb605d28a72d77eb83a1cae22f3df2eb8.svg) [@system](https://techcommunity.softwareag.com/u/system)\
**Post date:** [February 27, 2024, 8:14pm UTC](https://techcommunity.softwareag.com/t/calculate-last-3-years-dynamically/282736/5 "2024-02-27T20:14:24Z")

</div>

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