# calculating days

**URL:** <https://techcommunity.softwareag.com/t/calculating-days/90173>\
**Category:** Forum\
**Tags:** Adabas-Natural, Natural, Natural-on-Mainframes\
**Created:** [May 13, 2009, 11:22pm UTC](https://techcommunity.softwareag.com/t/calculating-days/90173 "2009-05-13T23:22:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Roger](https://avatars.discourse-cdn.com/v4/letter/r/c0e974/32.png) [@Roger](https://techcommunity.softwareag.com/u/Roger)\
**Post date:** [May 13, 2009, 11:22pm UTC](https://techcommunity.softwareag.com/t/calculating-days/90173/1 "2009-05-13T23:22:49Z")

</div>

I have 2 dates and I need to find the number of days between them.  
Or take the current date, convert it to a julian date and then subtract 560 days. take that date and compare it to another date.

Is it possible in Natural?

Been away too long.

Sincerely,

Roger

---

<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:** [May 13, 2009, 11:50pm UTC](https://techcommunity.softwareag.com/t/calculating-days/90173/2 "2009-05-13T23:50:40Z")

</div>

Easy enough.

If they are already date fields {format (D)}, you only need to subtract the two dates.

COMPUTE #NBR-DAYS = #DATE1 - DATE2

If they are not (D) fields, you would convert them to date fields using move edited:

```auto
IF #DATE-CYMD1 = MASK (YYYYMMDD)
  MOVE EDITED #DATE-CYMD1 TO #DATE1 (EM=YYYYMMDD)
ELSE
  do something else because the date is not in the format we are expecting.
END-IF
```

The mask check is necessary to prevent a Natural error.

For the second problem, don’t convert to Julian until you have the date you want. Convert to D format if needed, subtract 560 and then convert the D to Julian:

```auto
MOVE EDITED #DATE-CYMD TO #DATE (EM=YYYYMMDD)
SUBTRACT 560 FROM #DATE
MOVE EDITED #DATE (EM=YYYYJJJ) TO #DATE-J
```

---

<div class="post-metadata">

**Author:** ![Balaryan1](https://avatars.discourse-cdn.com/v4/letter/b/4da419/32.png) [@Balaryan1](https://techcommunity.softwareag.com/u/Balaryan1)\
**Post date:** [July 20, 2009, 3:36pm UTC](https://techcommunity.softwareag.com/t/calculating-days/90173/3 "2009-07-20T15:36:05Z")

</div>

Hi Jerome,

What is the essence of subtracting 560 from #DATE, which is of D format…??

---

<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 20, 2009, 6:40pm UTC](https://techcommunity.softwareag.com/t/calculating-days/90173/4 "2009-07-20T18:40:24Z")

</div>

> [@Balaryan](#):
>
> Hi Jerome,
> 
> What is the essence of subtracting 560 from #DATE, which is of D format…??

Roger wants to subtract 560 days for whatever reason.  
And Jerome said it would be better to subtract in D-Format than in other format. This is correct. You can calculate with D-Fields in a very easy way.

e.g.

```auto
#next-week := *DATX + 7
```

---

<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:57pm UTC](https://techcommunity.softwareag.com/t/calculating-days/90173/5 "2021-04-02T14:57:03Z")

</div>


