date comparison

Im trying to compare to date

the dates are the same nbut for some reason the long value of the date are not equal

here is a test that I make

System.out.println(" this date before if#################"+searchDate.getTime()+""+ searchDate+"#################### "+ ((java.sql.Date)vectTypeVisitIntervals.get(cpt)).getTime()+""+(java.sql.Date)vectTypeVisitIntervals.get(cpt));

and this is one of the output

this date before if#################11761947007342007-04-10#################### 11761560000002007-04-10

so when I compare two dates ,I dont have equal dates ?

although they are equal

thank you

[755 byte] By [linuxchilda] at [2007-11-27 0:25:57]
# 1
searchDateand(java.sql.Date)vectTypeVisitIntervals.get(cpt)are not exactly the same Time but DayThere are on the same Day, but one before another.If you want to ignore the time component, you can set those to zero.
rym82a at 2007-7-11 22:24:01 > top of Java-index,Java Essentials,Java Programming...
# 2
thnak you I did it it is working nowMessage was edited by: linuxchild
linuxchilda at 2007-7-11 22:24:01 > top of Java-index,Java Essentials,Java Programming...
# 3

May be I didn't explain very clearly.

Date contains Year, Month, Day which are Day Component and Hour, Minute, Second, Millisecond which are Time Component.

Here are the API document

http://java.sun.com/j2se/1.4.2/docs/api/java/util/Date.html#setHours(int)

http://java.sun.com/j2se/1.4.2/docs/api/java/util/Calendar.html#set(int,%20int)

Or you may try the following

// Only compare the date component and ignore the time component

public static void compareDate(Date dateIn1, Date dateIn2) throws ParseException {

SimpleDateFormat sdf = new SimpleDateFormat("ddMMyyyy");

String dateStr1 = sdf.format(dateIn1);

String dateStr2 = sdf.format(dateIn2);

Date date1 = sdf.parse(dateStr1);

Date date2 = sdf.parse(dateStr2);

if (date1.before(date2)) {

System.out.println("DATE1_BEFORE_DATE2");

} else if (date1.after(date2)) {

System.out.println("DATE1_AFTER_DATE2");

} else {

System.out.println("DATE1_EQUALS_DATE2");

}

}

rym82a at 2007-7-11 22:24:01 > top of Java-index,Java Essentials,Java Programming...