Compare date in numeric variables

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’…

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

   WRITE 'Latest data is ' DATA-1

Thanks in advance!

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)



Now you can

IF #D1 > #D2

1 Like

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.

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.

1 Like

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:

01 #DATA-1 (N8)
01 redefine #DATA-1
  02 #DATA1-A (A8)

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

1 Like

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.

1 Like