# Adding a date

**URL:** <https://techcommunity.softwareag.com/t/adding-a-date/75073>\
**Category:** Forum\
**Tags:** Adabas-Natural, Natural, Natural-on-Mainframes\
**Created:** [July 23, 2007, 5:15pm UTC](https://techcommunity.softwareag.com/t/adding-a-date/75073 "2007-07-23T17:15:39Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![sriramp](https://avatars.discourse-cdn.com/v4/letter/s/bc79bd/32.png) [@sriramp](https://techcommunity.softwareag.com/u/sriramp)\
**Post date:** [July 23, 2007, 5:15pm UTC](https://techcommunity.softwareag.com/t/adding-a-date/75073/1 "2007-07-23T17:15:39Z")

</div>

Hi,

How can we add some 5 years to a particular date, say today. So i want to have a date which is 5 years from today…

Tried adding to date, but it added to only the days.

Can anyone help me out!!

Thanks  
Sriram

---

<div class="post-metadata">

**Author:** ![Finn\_the\_Dane1](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/finn_the_dane1/32/132_2.png) [@Finn\_the\_Dane1](https://techcommunity.softwareag.com/u/Finn_the_Dane1)\
**Post date:** [July 23, 2007, 5:36pm UTC](https://techcommunity.softwareag.com/t/adding-a-date/75073/2 "2007-07-23T17:36:22Z")

</div>

Not a very elegant or sofisticated solution but as far as I can see it works 😉  
Except: the technique below doesn’t handle “feb 29”!

DEFINE DATA LOCAL  
1 D (D)  
1 A (A10)  
1 REDEFINE A  
2 YYYY (N4)  
END-DEFINE  
MOVE \*DATX TO D  
MOVE EDITED D (EM=YYYYMMDD) TO A  
ADD 5 TO YYYY  
MOVE EDITED A TO D (EM=YYYYMMDD)  
DISPLAY D  
END

---

<div class="post-metadata">

**Author:** ![Matthias1](https://avatars.discourse-cdn.com/v4/letter/m/9fc348/32.png) [@Matthias1](https://techcommunity.softwareag.com/u/Matthias1)\
**Post date:** [July 23, 2007, 7:13pm UTC](https://techcommunity.softwareag.com/t/adding-a-date/75073/3 "2007-07-23T19:13:47Z")

</div>

To get the same day in the next year, you can code:

```auto
add 366 to #date
```

The problem is: In case of an included leap day, you have to code:

```auto
add 367 to #date
```

But maybe you can combine this with the leap year test discussed here: [http://tech.forums.softwareag.com/viewtopic.php?t=7298](http://tech.forums.softwareag.com/viewtopic.php?t=7298)

---

<div class="post-metadata">

**Author:** ![Finn\_the\_Dane1](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/finn_the_dane1/32/132_2.png) [@Finn\_the\_Dane1](https://techcommunity.softwareag.com/u/Finn_the_Dane1)\
**Post date:** [July 24, 2007, 12:43pm UTC](https://techcommunity.softwareag.com/t/adding-a-date/75073/4 "2007-07-24T12:43:09Z")

</div>

Hi Sriam  
I’ve improved my algorithm to take care of leap year and made it into a subprogram.  
Finn

* * *

- Subprogram to add a number of years to a date
- Finn the Dane - July 2007  
DEFINE DATA PARAMETER  
1 IN-PARMS  
2 IN-DATE (D)  
2 IN-ADD-YEARS (I2)  
1 OUT-DATE (D)  
LOCAL  
1 A (A10)  
1 REDEFINE A  
2 YYYY (N4)  
2 MM (N2)  
2 DD (N2)  
END-DEFINE

MOVE EDITED IN-DATE (EM=YYYYMMDD) TO A  
ADD IN-ADD-YEARS TO YYYY  
IF NOT (A IS (D)) /\* Test for leap year  
MOVE 3 TO MM /\* and move to 1st of March if new year is not a leap year  
MOVE 1 TO DD  
END-IF  
MOVE EDITED A TO OUT-DATE (EM=YYYYMMDD)  
END

---

<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:** [April 2, 2021, 2:48pm UTC](https://techcommunity.softwareag.com/t/adding-a-date/75073/5 "2021-04-02T14:48:34Z")

</div>


