× 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.




On 28/03/2006, at 7:35 AM, praveen gunda wrote:

I think IBM should have taken care of this, similar to how they have taken
care of this.

2006-01-31 + %months(1) = 2006--2-28

2006-02-31 is not a valid date so the system has to take care of it otherwise date exceptions would occur.

2006-02-28 is a valid date and adding one month to it is 2006-03-28. Just because 28 happens to be the last day of February (mostly) doesn't automatically mean adding one month to it will give the last day of the next month.

The system only adjusts invalid dates.

If you always want the last day of the month then calculate it yourself. It's very easy.

Also,
2006-01-31 + %months(2) should be consistent with 2006-01-31 + %months(1) +
%months(1)

No it shouldn't. Read the manual.

Adding 2 months or adding 1 month + 1 months should be same right?

No it shouldn't. Read the manual.

I write a lot in Java, and have never came across such a problem.

Java has its own inconsistencies. Compile and run:

import java.util.*;
public class PraveenDate
{
  public static void main(String[] args)
  {
Date d = new Date(106, 0, 31); // 2006-01-31 -- Java's inconsistent counting practices
    System.out.println(d);
    d.setMonth(1);
    System.out.println(d);
    d.setMonth(2);
    System.out.println(d);
    d.setMonth(3);
    System.out.println(d);
    d.setMonth(4);
    System.out.println(d);
  }
}

> java PraveenDate
  Tue Jan 31 00:00:00 GMT 2006
  Fri Mar 03 00:00:00 GMT 2006
  Fri Mar 03 00:00:00 GMT 2006
  Mon Apr 03 00:00:00 GMT 2006
  Wed May 03 00:00:00 GMT 2006  

And look closely at the printed dates. Why are the second and third the same date? Why does adding 1 month to 2006-01-31 not give 2006-02-28? Easy to explain once you understand what is happening but I'd rather have RPG's behaviour than Java's.

Regards,
Simon Coulter.
--------------------------------------------------------------------
   FlyByNight Software         AS/400 Technical Specialists

   http://www.flybynight.com.au/
   Phone: +61 3 9419 0175   Mobile: +61 0411 091 400        /"\
   Fax:   +61 3 9419 0175                                   \ /
                                                             X
                 ASCII Ribbon campaign against HTML E-Mail  / \
--------------------------------------------------------------------




As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

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.