# Compare date in numeric variables

**URL:** <https://techcommunity.softwareag.com/t/compare-date-in-numeric-variables/263913>\
**Category:** Forum\
**Tags:** Adabas-Natural, Natural, natural-mainframe\
**Created:** [September 20, 2022, 8:38pm UTC](https://techcommunity.softwareag.com/t/compare-date-in-numeric-variables/263913 "2022-09-20T20:38:49Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Priscilla\_G\_Souza](https://avatars.discourse-cdn.com/v4/letter/p/c4cdca/32.png) [@Priscilla\_G\_Souza](https://techcommunity.softwareag.com/u/Priscilla_G_Souza)\
**Post date:** [September 20, 2022, 8:38pm UTC](https://techcommunity.softwareag.com/t/compare-date-in-numeric-variables/263913/1 "2022-09-20T20:38:50Z")

</div>

#### Hello! What is the best and the most correct way to discover the latest data comparing 2 datas contained in numeric variables (N8) in format YYYYMMDD?

Ex: I tried this, but I don’t know if this has ‘flaws’..

```auto
1 DATA-1 (N8) /* YYYYMMDD
2 DATA-2 (N8) /* YYYYMMDD

IF DATA-1 > DATA-2
   WRITE 'Latest data is ' DATA-1
END-IF

```

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![MICK.FITZPATRICK](https://avatars.discourse-cdn.com/v4/letter/m/b5ac83/32.png) [@MICK.FITZPATRICK](https://techcommunity.softwareag.com/u/MICK.FITZPATRICK)\
**Post date:** [September 20, 2022, 8:56pm UTC](https://techcommunity.softwareag.com/t/compare-date-in-numeric-variables/263913/2 "2022-09-20T20:56:48Z")

</div>

Define two variables

1 #D1 (D)

1 #D2 (D)

Then (apologies if my syntax is incorrect below as I’m doing this from memory – no longer have access to a Natural editor)

MOVE EDITED DATA-1 to #D1 (EM=YYMMDD)

MOVE EDITED DATA-2 to #D2 (EM=YYMMDD)

Now you can

IF #D1 \> #D2

---

<div class="post-metadata">

**Author:** ![Priscilla\_G\_Souza](https://avatars.discourse-cdn.com/v4/letter/p/c4cdca/32.png) [@Priscilla\_G\_Souza](https://techcommunity.softwareag.com/u/Priscilla_G_Souza)\
**Post date:** [September 20, 2022, 9:13pm UTC](https://techcommunity.softwareag.com/t/compare-date-in-numeric-variables/263913/3 "2022-09-20T21:13:46Z")

</div>

Hi Mick!  
I tried to move the numeric variables to D variables, but when I STOW the program, I receive an error, probably because I have to move to alphanumeric variables first… but my question is: is there a simple way to obtain a correct result (just like comparing the 2 numeric variables or is it necessary to move to alpha, and then to D variables to compare them)?

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![Ralph\_Zbrog](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/ralph_zbrog/32/78_2.png) [@Ralph\_Zbrog](https://techcommunity.softwareag.com/u/Ralph_Zbrog)\
**Post date:** [September 20, 2022, 9:19pm UTC](https://techcommunity.softwareag.com/t/compare-date-in-numeric-variables/263913/4 "2022-09-20T21:19:23Z")

</div>

YYYYMMDD format will keep the values in ascending sequence. Your original comparison will work fine. There is no need to convert to D format.

D format is handy, though. It allows you to compute elapsed time very easily.

---

<div class="post-metadata">

**Author:** ![Douglas\_Kelly](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/douglas_kelly/32/102_2.png) [@Douglas\_Kelly](https://techcommunity.softwareag.com/u/Douglas_Kelly)\
**Post date:** [September 20, 2022, 9:32pm UTC](https://techcommunity.softwareag.com/t/compare-date-in-numeric-variables/263913/5 "2022-09-20T21:32:40Z")

</div>

I agree with Ralph - your original comparison works fine.

If, as Ralph mentions, you want to compute elapsed time between two dates, D format is handy. Rather than moving the numeric dates to alpha, just redefine them:

```auto
01 #DATA-1 (N8)
01 redefine #DATA-1
  02 #DATA1-A (A8)
...
MOVE EDITED #DATA-1-A TO #D1 (EM=YYYYMMDD)
...

```

Now you can use the format (D) field in computations (as well as comparisons).

---

<div class="post-metadata">

**Author:** ![Eugene.Miklovich](https://avatars.discourse-cdn.com/v4/letter/e/ce73a5/32.png) [@Eugene.Miklovich](https://techcommunity.softwareag.com/u/Eugene.Miklovich)\
**Post date:** [September 21, 2022, 1:35pm UTC](https://techcommunity.softwareag.com/t/compare-date-in-numeric-variables/263913/6 "2022-09-21T13:35:20Z")

</div>

As Ralph pointed out you can compare D/T to D/T variables directly (even to \*DATX/\*TIMX). Internally Date and Time variables are packed numbers representing the elapsed days/seconds from the beginning of time (as defined by Software AG or Copernicus - i.e. the beginning of the Gregorian Calendar in 1582). So that is why date arithmetic is easy and efficient.

---

<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:** [March 20, 2023, 1:35pm UTC](https://techcommunity.softwareag.com/t/compare-date-in-numeric-variables/263913/7 "2023-03-20T13:35:50Z")

</div>

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