× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Here is some more relevant information from the latest Club Tech from AS/400
Network

QUOTE

3. POTENTIAL DATE ARITHMETIC GOTCHA EXPOSED
Several readers wrote in to report a bug in the way RPG handles data
arithmetic, specifically citing that the SubDur op-code intermittently
returns erroneous information.

Readers reported that the problem sometimes occurs when subtracting the end
of one month from the end of another month and requesting the result in
terms of months. For example, subtracting the end of March from the end of
April returns the value 0 rather than 1 for the number of months. Consider
the following code:

     C     DateFld1      SubDur    DateFld2      Months:*M

When field DateFld1 is April 30, 2001 (2001-04-30) and field DateFld2 is
March 31, 2001 (2001-03-31), field Months contains the value 0 rather than 1.

Though some expected a PTF to fix the problem, this is not a bug! RPG is
working exactly as designed. It is important to note this behavior so that
your applications work properly. As you'll soon see, it is possible to first
add a specific duration to a date and then subtract that same duration with
the resulting date not equaling the original date!

>From the ILE RPG Reference:

A month can contain 28, 29, 30, or 31 days. A year can contain 365 or 366
days. Because of this inconsistency, the following operations can give
unexpected results:

* Adding or subtracting a number of months (or calculating a duration in
  months) with a date that is on the 29th, 30th, or 31st of a month
* Adding or subtracting a number of years (or calculating a duration in
  years) with a February 29 date.

The following rules are used:
* When months or years are added or subtracted, the day portion remains
  unchanged if possible. For example, 2000-03-15 + %MONTHS(1) is 2000-04-15.
* If the addition or subtraction would produce a nonexistent date (for
  example, April 31), the last day of the month is used instead.
* Any month or year operation that changes the day portion is not
  reversible. For example, 2000-03-31 + %MONTHS(1) is 2000-04-30 changes the
  day from 31 to 30. You cannot get back the original 2000-03-31 by
  subtracting one month.

  The operation 2000-03-31 + %MONTHS(1) - %MONTHS(1) becomes 2000-03-30.

* The duration between two dates is one month if the later date minus
  one month gives the first date. For example, the duration in months
  (rounded down) between 2000-03-31 and 2000-04-30 is 0 because
  2000-04-30 - %MONTHS(1) is 2000-03-30 (not 2000-03-31).

UNQUOTE

MacWheel99@aol.com (Alister Wm Macintyre) (Al Mac)
BPCS 405 CD Manager / Programmer @ Global Wire Technologies Incorporated
http://www.globalwiretechnologies.com = new name same quality wire
engineering company: fax # 812-424-6838



As an Amazon Associate we earn from qualifying purchases.

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.