talend date conversion issue

Six Stars

talend date conversion issue

 

Hi have XML field that I am extracting as one field and has timestamp of format (yyyy-MM-dd'T'HH:mm:ss.SSSSSS).

Now I want to only get yyyy-MM-dd for the date comparison so that I can do the incremental load like ( yyy-MM-dd)<= 7 (for 7 days incremental).

Job.JPG

 

On my tjava I have:

context.runDate=TalendDate.parseDate("yyyy-MM-dd","2017-07-03")

 

On the tMap, Expression builder I have to change the format of the timestamp to yyyy-MM-dd :

TalendDate.parseDate("yyyy-MM-dd",TalendDate.formatDate("yyyy-MM-dd",TalendDate.parseDate("yyyy-MM-dd'T'HH:mm:ss.SSSSSS",row2.timeStamp)))

Then I have below logic for date compare:

(TalendDate.compareDate(Var.datevalue,context.runDate,"yyyy-MM-dd"))<=1

 

tmap.JPG

 

 

tJavaRow.JPG

 

 

When I run the job it runs fine but it doesn't load as logic but will load the entire data.

 

Can somebody please help me on this.

 

Tags (1)

Accepted Solutions
Moderator

Re: talend date conversion issue

Hi,

Do you mean your expression is not working on row2.timeStamp? Did you use your expression in expression filter or expression field?

1.png

Best regards

Sabrina

--
Don't forget to give kudos when a reply is helpful and click Accept the solution when you think you're good with it.

All Replies
Five Stars tdz
Five Stars

Re: talend date conversion issue

Hello Brawal,

 

I think there is a problem in your expression :

(TalendDate.compareDate(Var.datevalue,context.runDate,"yyyy-MM-dd"))<=1

 

Because the method 'compareDate' in Talend accepts the values :

• CompareDate returns 0 if d1 = d2
• CompareDate returns 1 if d1 > d2
• CompareDate returns -1 if d1 < d2

In your case, your expression is allways true, that's why it loads the entire data.

 

Try this :

(TalendDate.compareDate(Var.datevalue,context.runDate,"yyyy-MM-dd"))<1

 

I hope this answer will help you.

 

TD

Six Stars

Re: talend date conversion issue

Thanks you for  that correction. I see now data is not loaded at all. Is the logic wrong? If so can somebody please suggest me the fix?

Moderator

Re: talend date conversion issue

Hi,

Do you mean your expression is not working on row2.timeStamp? Did you use your expression in expression filter or expression field?

1.png

Best regards

Sabrina

--
Don't forget to give kudos when a reply is helpful and click Accept the solution when you think you're good with it.
Six Stars

Re: talend date conversion issue

Sorry I found a solution to this. Thanks for all the replies. Really appreciated.

Moderator

Re: talend date conversion issue

Hello,

Thanks for your feedback.Would you mind sharing your solution on forum?

Best regards

Sabrina

--
Don't forget to give kudos when a reply is helpful and click Accept the solution when you think you're good with it.

What’s New for Talend Spring ’19

Watch the recorded webinar!

Watch Now

Definitive Guide to Data Quality

Create systems and workflow to manage clean data ingestion and data transformation.

Download

Tutorial

Introduction to Talend Open Studio for Data Integration.

Watch

Downloads and Trials

Test drive Talend's enterprise products.

Downloads