One Star

compare 2 dates

how can i make comparaison between 2 dates with Tmap. I used ">" but it doesn't defined for date type...
i find a solution consisting using a tJavarow and getTime() function in output to have a long type and not date type...
but my problem now is to transform from long type to date type so i can insert data in oracle database...
please help
Tags (1)
9 REPLIES
Community Manager

Re: compare 2 dates

Hi
how can i make comparaison between 2 dates with Tmap. I used ">" but it doesn't defined for date type...

Which version of TOS did you use? the syntax">" can be used in tMap.
but my problem now is to transform from long type to date type so i can insert data in oracle database...

Can you upload a screenshot of your job and what are your expected result?
Feel free to post your questions!
Best regards
shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
Employee

Re: compare 2 dates

Hello,
In Java date comparisons are made using the compareTo method
For example : row1.date1.compareTo(row1.date2)>0
Regards,
One Star

Re: compare 2 dates

Hi,
could you give us the syntax for date comparison in PERL ?
Thanks
One Star

Re: compare 2 dates

thank u for replying...
I resolved the problem ...
Employee

Re: compare 2 dates

could you give us the syntax for date comparison in PERL ?

In Perl, the "problem" is completely different. A date is a string. Can you show us your date format to give informations about comparison method?
One Star

Re: compare 2 dates

Thanks:
input format in file: "2007-12-15"
How to filter with a comparison like date > 2007-12-01.
Should the field be defined as a string or a date ?
Thanks
Employee

Re: compare 2 dates

Thanks:
input format in file: "2007-12-15"

This is the easiest format for comparison, you're lucky! A simple string comparison or a numeric comparison works. Here is the numeric comparison:
$date1 > '2007-12-01'

Should the field be defined as a string or a date ?

Having string or date as data type in the schema will have absolutely no consequence on the comparison you will write.
For your information, I checked with the following Perl onliners:
$ perl -e '@dates = qw/2009-06-23 1954-12-08 2007-12-10/; print join("\n", sort {$a <=> $b} @dates), "\n";'
1954-12-08
2007-12-10
2009-06-23
$ perl -e '@dates = qw/2009-06-23 1954-12-08 2007-12-10/; print join("\n", sort {$a cmp $b} @dates), "\n";'
1954-12-08
2007-12-10
2009-06-23

First I used a numeric sort, then a string sort, and both works fine.
One Star

Re: compare 2 dates

Thanks !
Seven Stars

Re: compare 2 dates

Hi @rnddrnd,

 

There is a in built system function for comparing dates

  • TalendDate.compareDate(mydate1,mydate2)==1 means mydate1 is greater that mydate2 
  • TalendDate.compareDate(mydate1,mydate2)==-1 means mydate1 is less than  than mydate2
  • TalendDate.compareDate(mydate1,mydate2)==0 means mydate1 is equal to mydate2

By this way you can compare two dates inside talend 

Note:Both Should be in date data type if that is in string format use TalendDate.parseDate to convert to date format


Thanks,

Kasthuri