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



Just a couple of thoughts.

The SQL date math with DB2 is pretty slick. If you're working with
dates that are already in the database it might just be easier to do
the calculation there, rather than in Java. Something like DAYS(col1)
- DAYS(col2). If you need the current time stamp you can select it as
a constant from sysibm/sysdummy1. For more info on this approach you
may find this page useful:
http://www.ibm.com/developerworks/db2/library/techarticle/0211yip/0211yip3.html

So far as dealing with dates in Java, it's never been pretty. To be
guaranteed that you're comparing apples to apples, especially when
doing date math, you should use a GregorianCalendar. If you
instantiate two GregorianCalendars, one for each of the dates your
working with there are some methods provided by the Calendar interface
which should help you easily accomplish your task. Methods before(),
after(), equal(), and getTimeInMillis() look very promising. If you
instantiate the GregorianCalendar objects correctly there shouldn't be
an issue with DST etc.

Check out the JavaDoc:
http://java.sun.com/j2se/1.4.2/docs/api/java/util/GregorianCalendar.html
http://java.sun.com/j2se/1.4.2/docs/api/java/util/Calendar.html
http://java.sun.com/j2se/1.4.2/docs/api/java/util/Date.html

Cheers!
Joe




On Jan 27, 2008 10:51 AM, Jon Paris <Jon.Paris@xxxxxxxxxxxxxx> wrote:
Anyone got some Java code that will do a simple "days between two
dates" calculation? There are no times involved - just simple dates.

I have Google'd for a solution but they all seem to involve mucking
about with multiplication etc. Most of them also seem to have at
least one person pointing out that there will be problems with DST,
or rounding, or ...

Surely in this "all powerful" language there is an easy solution for
such a simple business problem? In RPG it is a simple %Diff - do I
really need 20+ lines of Java to achieve the same thing?

Jon Paris

www.Partner400.com
www.SystemiDeveloper.com


--
This is the Java Programming on and around the iSeries / AS400 (JAVA400-L) mailing list
To post a message email: JAVA400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/java400-l
or email: JAVA400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/java400-l.



As an Amazon Associate we earn from qualifying purchases.

This thread ...

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.