ofbiz-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "John Martin" <pbweb...@gmail.com>
Subject Re: Date Comparison Function
Date Fri, 06 Oct 2006 17:14:48 GMT
The problem with that is that comparing datetime means that 10/06/2006
12:00:01 != 10/06/2006 18:30:00.  I just want to see if a Date is the
same, before, or after another.  The time messes up the tests.

I think using the commons/validator is the right thing to do since the
less code we write, the less we have to maintain.  On the otherhand,
my method is short and sweet.

     * compares two dates (excluding time) to determine if date A is
equal, before or after date B
     * @param dateA     a java.util.Date object
     * @param dateB     a java.util.Date object
     * @return  int     a value of zero (0) indicates the dates are
equal; a value less than zero (< 0) date A is prior to B; and a
     *                  value greater than zero (> 0) indicates date A
occurs after B
    public static int compareDates(java.util.Date dateA, java.util.Date dateB) {
        String strDateA = UtilDateTime.toDateString(dateA, "yyyyMMdd");
        String strDateB = UtilDateTime.toDateString(dateB, "yyyyMMdd");
        return strDateA.compareTo(strDateB);

View raw message