 # calculating days

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

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:

``````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:

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

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.

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