[resolved] DateDiff troubles

One Star

[resolved] DateDiff troubles

Hi,
I try to use Talend.DateDiff but I don't understand the return value:
I use a TjavaRow to print the number of days between a date and current date.
Date_contractuelle_de_remise_du_document is coming from a excel spreadsheet and is french formatted 'dd/MM/yyyy'
System.out.println(TalendDate.parseDate("dd/MM/yyyy",input_row.Date_contractuelle_de_remise_du_document)+ " "
+ TalendDate.getCurrentDate() + " " + TalendDate.diffDate(TalendDate.getCurrentDate(),TalendDate.parseDate("dd/MM/yyyy",input_row.Date_contractuelle_de_remise_du_document),"dd"));
Result from execution is :
Sat Jan 10 00:02:00 CET 11 Tue Oct 18 14:49:24 CEST 2011 730768
Sat Jan 10 00:02:00 CET 11 Tue Oct 18 14:49:24 CEST 2011 730768
Sat Jan 10 00:02:00 CET 11 Tue Oct 18 14:49:24 CEST 2011 730768
Sat Jan 10 00:02:00 CET 11 Tue Oct 18 14:49:24 CEST 2011 730768
Tue Jan 13 00:06:00 CET 11 Tue Oct 18 14:49:24 CEST 2011 730765
Why do I get 730765 days between 13th of January and 18th of october ?

Accepted Solutions
One Star

Re: [resolved] DateDiff troubles

I found a solution, but not really an explanation !
If I parse using "dd/MM/yy", il works. So even if I parse the excel string cell in "dd/MM/yyyy", I think I get dd/MM/00yy. So the difference of 730xxx days comes from that silly interpretation of a string from excel in dd/MM/yyyy format.

All Replies

Re: [resolved] DateDiff troubles

Hi miniquick
Try the following Code:
System.out.println(TalendDate.parseDate("dd/MM/yyyy",input_row.Date_contractuelle_de_remise_du_document)+ " " 
+ TalendDate.getDate("dd/MM/yyyy") + " " + TalendDate.diffDate(TalendDate.parseDate("dd/MM/yyyy",TalendDate.getDate("dd/MM/yyyy")),TalendDate.parseDate("dd/MM/yyyy",input_row.Date_contractuelle_de_remise_du_document),"dd"));

Regards
Brandon
One Star

Re: [resolved] DateDiff troubles

Thanks for truying to help me, but I got the same result.
One Star

Re: [resolved] DateDiff troubles

Hi
It seems like like the locale is taken wrongly in your time CET and CEST.
One Star

Re: [resolved] DateDiff troubles

I found a solution, but not really an explanation !
If I parse using "dd/MM/yy", il works. So even if I parse the excel string cell in "dd/MM/yyyy", I think I get dd/MM/00yy. So the difference of 730xxx days comes from that silly interpretation of a string from excel in dd/MM/yyyy format.