Hi all,
following problem is bothering me and I can't find any reasonable explanation and a solution. Perhaps someone could enlighten me.
I have an application that calculates date difference (in days) - in a Search mask and in a Details mask. In the first mask I use days to filter out records with a duration search criteria (Search mask) and I do this with an SQL query:
WHERE...
...
AND DECODE(TRUNC(to_number(SUBSTR((close_date -
create_date),1,instr(close_date - create_date,' ')))), NULL,
TRUNC(to_number(SUBSTR((systimestamp - create_date),1,instr(systimestamp -
create_date,' ')))), TRUNC(to_number(SUBSTR((close_date -
create_date),1,instr(close_date - create_date,' ')))) ) >=140
AND DECODE(TRUNC(to_number(SUBSTR((close_date -
create_date),1,instr(close_date - create_date,' ')))), NULL,
TRUNC(to_number(SUBSTR((systimestamp - create_date),1,instr(systimestamp -
create_date,' ')))), TRUNC(to_number(SUBSTR((close_date -
create_date),1,instr(close_date - create_date,' ')))) ) <=140
In this special case I try to find out all the records that have a duration of 140 days.
In the second mask (Details) I show the record details, including its duration. This is done with the following java code:
public static Integer getDuration(Date caseDate, Date closeDate) {
Date beginDate = caseDate;
Date endDate = (closeDate != null)? closeDate: new Date();
long difference = endDate.getTime() - beginDate.getTime();
int daysDiff = (int) (difference / (24.0 * 60 * 60 * 1000));
return new Integer(daysDiff);
}
My problem is that when I search, I find some records that do correspond to the search criteria. For instance I find 4 records and all of them have a duration of 140 days. That's according to Oracle. But when I open the Details mask for some of them I get a duration of 139 days for example. So somehow Java and Oracle calculate date differences in a different way. It seems that in Oracle some rounding is being made, but I can't find where this happens. So any suggestions would be helpful. Thanks!
Greets, almaak