One Star

TalendDate.diffDate wrong results?

With a tMap i am joining a csv file (row4) and a lookup csv file (row3) into a MySQL table. They have a key id for the inner join.
Having
row4.DATA_INVIO= 2013-04-01 12:47:49 type Date "yyyy-MM-dd HH:mm:ss"
row3.DATA_CREAZIONE= 2013-04-01 12:30:57 type Date "yyyy-MM-dd HH:mm:ss"
in the Var box of the tMap I calculate the difference in seconds between two dates:
TalendDate.diffDate(row4.DATA_INVIO, row3.DATA_CREAZIONE, "ss")
Result= -42188 WRONG!
But if in the Var box of the tMap I put this (same dates)...
TalendDate.diffDate(TalendDate.parseDate("yyyy-MM-dd HH:mm:ss","2013-04-01 12:47:49"), TalendDate.parseDate("yyyy-MM-dd HH:mm:ss","2013-04-01 12:30:57"), "ss")
Result = 1012 GOOD!
What is happening????
I'm having the same problems with many raws, it's not random, it seems that some rows always give wrong results...
Any suggestion is highly appreciated.
Stefano
5 REPLIES

Re: TalendDate.diffDate wrong results?

could it be that you had dates in your dataset as Strings - when you had value -42188
and then by CASTing them into Date - you have the correct value?
Seven Stars

Re: TalendDate.diffDate wrong results?

Try printing row4.DATA_INVIO and row3.DATA_CREAZIONE to the console to check the timezone offset on them?
One Star

Re: TalendDate.diffDate wrong results?

could it be that you had dates in your dataset as Strings - when you had value -42188
and then by CASTing them into Date - you have the correct value?

ok, I have defined the text delimited metadata date field from Date to String
row4.DATA_INVIO type String
row3.DATA_CREAZIONE type String
then I have put this formula:
TalendDate.diffDate(TalendDate.parseDate("yyyy-MM-dd HH:mm:ss",row4.DATA_INVIO), TalendDate.parseDate("yyyy-MM-dd HH:mm:ss",row3.DATA_CREAZIONE), "ss")
and it works well now.
The question remains: why it doesn't work with Date datatype?
Thank you very much for the advice.
Stefano
One Star

Re: TalendDate.diffDate wrong results?

Try printing row4.DATA_INVIO and row3.DATA_CREAZIONE to the console to check the timezone offset on them?

How can i print to the console? I don't know it...
Thank you
Four Stars

Re: TalendDate.diffDate wrong results?

Hi

System.out.println("value " +value);
Ex: System.out.println("value " +TalendDate.diffDate(TalendDate.parseDate("yyyy-MM-dd HH:mm:ss",row4.DATA_INVIO), TalendDate.parseDate("yyyy-MM-dd HH:mm:ss",row3.DATA_CREAZIONE), "ss"));
use the above syntax in tjava/tjavarow/tjavaflex
For more help on I\O Streams in java please refer the link: http://way2java.com/io/system-out-println/

thanks
Anil Kumar Burri
http://anilkumarburri.wordpress.com/