Calculate the age from the current date and the date of birth

One Star

Calculate the age from the current date and the date of birth

Hello;

I wish I calculate the age of a person from his date of birth and compared to the current date?
I've done me is this:

TalendDate.diffDate(TalendDate.parseDate("dd-MM-yyyyy","11-08-2013"),TalendDate.parseDate("dd-MM-yyyyy","20-01-2000"),"dd")

I'd like it to be dynamic I do not know if we can do that.??
TalendDate.diffDate(TalendDate.parseDate("dd-MM-yyyyy","TalendDate.getCurrentDate()"),TalendDate.parseDate("dd-MM-yyyyy","row6.dateNaiss"),"dd")

But it shows me an error: Type mismatch: can not convert long to float
I also tried it
test.agePatient==null?(String.valueOf((TalendDate.diffDate(TalendDate.getCurrentDate(), row6.dateNaiss,"yyyy"))).toString():test.agePatient);
and it also
test.agePatient==null? String.((TalendDate.diffDate(TalendDate.getCurrentDate(),row6.dateNaiss,"yyyy"))).(TalendDate.parseDate(test.agePatient));
But I still have errors
Can you help me please?
Regards.
Seven Stars

Re: Calculate the age from the current date and the date of birth

Try to understand what the functions actually do so you can pass the correct parameters to them.
Assuming dateNaiss is a Date not a String: TalendDate.diffDateFloor(TalendDate.getCurrentDate(),row6.dateNaiss,"yyyy")
Your type mismatch error is coming from somewhere else in your job. Look at the Code tab to see exactly where.
One Star

Re: Calculate the age from the current date and the date of birth

Hi,
thank you for responding so quickly Smiley Very Happy
look, in my MySQL database, I have a date of birth that is like this: dd-mm-yyyy, Example 09-11-1984. and I would like to calculate the age of the person using the current date.
Seven Stars

Re: Calculate the age from the current date and the date of birth

If it's a Date in MySQL and you're reading it into Talend as a Date then the format in which it's displayed is irrelevant and the expression I gave you will do what you want.
One Star

Re: Calculate the age from the current date and the date of birth

thanks for your answer but, i didn't understand you, please can you give me a concret exemple?
Regards
Seven Stars

Re: Calculate the age from the current date and the date of birth

What didn't you understand? Just use the expression I gave you...
One Star

Re: Calculate the age from the current date and the date of birth

i try to do your expression, but, i have a mismatch: can not convert long to float.
Help me please
Moderator

Re: Calculate the age from the current date and the date of birth

Hi,
It is helpful to give us your job screenshots so that we can get your current job situation.
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.
One Star

Re: Calculate the age from the current date and the date of birth

Hi,
Attached my screen printed job talend
Best regards,
Slim
One Star

Re: Calculate the age from the current date and the date of birth

Hi,
Attached my screen printed job talend
Best regards,
Slim
Seven Stars

Re: Calculate the age from the current date and the date of birth

Note the restrictions: each image must be less than 1024x768 pixels and 200 KB.
As I said before, your type mismatch error is coming from somewhere else in your job. Look at the Code tab to see exactly where.
One Star

Re: Calculate the age from the current date and the date of birth

Hi,
Attached my screen printed job talend
Best regards,
Slim
One Star

Re: Calculate the age from the current date and the date of birth

Does anyone can help me?
Seven Stars

Re: Calculate the age from the current date and the date of birth

For the third time: Look at the Code tab (bottom-left of your design space) to see exactly where your type mismatch error is coming from (click on the red mark)!
If you don't read and follow our responses then no, we can't help you.
Moderator

Re: Calculate the age from the current date and the date of birth

Hi,
Next to the Designer tab there is a Code tab that lets you view the source code for the entire Job: TalendHelpCenterSmiley Very Happyesign workspace
Or else there is Code view next to the Outline that shows the generated code for the selected component.
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.