[resolved] Integer Conversion Problem

One Star

[resolved] Integer Conversion Problem

I am a noob to Talend but thanks to the forums I am learning quickly.  I am in T-Map and having a conversion problem:

TalendDate.diffDate(TalendDate.parseDate("yyyy-MM-dd",row1.Patient_Birth_Dt), TalendDate.parseDate("yyyy-MM-dd",row1.Date_of_Service))

My dates are in this format in the original file 20140404 (yyyy-MM-dd) as a string VARCHAR(8)
I have tried Integer.ParseInt but it's not working.  

I am trying to calculate Age.  It is an INT on the MySQL table.

As a side note, how would I do an UPDATE query for the row in the mapping?  I tried using the Tmysql-Row function but it didn't seem to work.  I would rather it work in T-Map if possible.
One Star

Re: [resolved] Integer Conversion Problem

First of all the 20140404 date is not in yyyy-MM-dd format... it should be yyyyMMdd.

Second... the diffDate works like date1-date2 which means the first date should be the later one, otherwise you'll get a negative value... in your case should be current date minus date of birth:
TalendDate.diffDate(TalendDate.parseDate("yyyyMMdd",row1.Date_of_Service), TalendDate.parseDate("yyyyMMdd",row1.Patient_Birth_Dt))

Third... using the diffDate you should specify what you want to get... difference in days, months, years etc. I'm not sure what is the default if you don't specify it but I would think days. For your case the expression would be:
TalendDate.diffDate(TalendDate.parseDate("yyyyMMdd",row1.Date_of_Service), TalendDate.parseDate("yyyyMMdd",row1.Patient_Birth_Dt), "yyyy")

Fourth point... the data type returned by the diffDate function is long and your output field is integer so you need to convert it like this:
(int)TalendDate.diffDate(TalendDate.parseDate("yyyyMMdd",row1.Date_of_Service), TalendDate.parseDate("yyyyMMdd",row1.Patient_Birth_Dt), "yyyy")

I think this should work for you...
One Star

Re: [resolved] Integer Conversion Problem

Wow that worked like a charm.  Thank you so much for the help and responding.  I thought it was just an integer problem or at least they way I was converting it.  You had many good points in there so I appreciate the teaching.
One Star

Re: [resolved] Integer Conversion Problem

My pleasure Smiley Happy
Regarding the UPDATE query you can just use normal tMysqlOutput but remember to specify a key that will be used for the UPDATE and set the 'Action on data' in the component properties to 'update'.


Talend named a Leader.

Get your copy


Kickstart your first data integration and ETL projects.

Download now

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

Have you checked out Talend’s 2019 Summer release yet?

Find out about Talend's 2019 Summer release


Talend Summer 2019 – What’s New?

Talend continues to revolutionize how businesses leverage speed and manage scale

Watch Now

6 Ways to Start Utilizing Machine Learning with Amazon We Services and Talend

Look at6 ways to start utilizing Machine Learning with Amazon We Services and Talend