Skip to main content
Announcements
A fresh, new look for the Data Integration & Quality forums and navigation! Read more about what's changed.
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Calculate age from current date and date of birth

Hello,

I would like to ask this question please:

I would like to calculate the age of employees from the current date and date of birth.

The date of birth format is as follows: 10/02/1980

What is the java code that I have to put in the variable?

Here is a screenshot:0683p000009M4i5.png

Thank you very much. 

Labels (3)
1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

@a_benlazreg 

 

I tried a slightly different method and results are as below.

 

The first value was 10-02-1980 in dd-mm-yyyy format

0683p000009M4jN.png

 

The next input value was 10-05-1980. Current date is 19-04-2019. So we have not reached the DoB for 2019 for this person and age should be 1 year less than previous sample.

0683p000009M4hi.png

 

Now the function used in tMap and it is as shown below.

0683p000009M4h3.png

 

TalendDate.diffDateFloor(TalendDate.getCurrentDate(),row1.dob,"yyyy") 

Hope your query is resolved by this method.

 

There are other diff date functions also available in Talend tMap. Please pick the function according to your specific requirement.

0683p000009M3oE.png

 

If the answer has helped you, please spend a second to mark the topic as resolved. Kudos are also welcome 🙂

 

Warm Regards,
Nikhil Thampi

Please appreciate our Talend community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved 🙂

 

View solution in original post

5 Replies
Anonymous
Not applicable
Author

This code will do this for you....

Date myBirthday = routines.TalendDate.parseDate("yyyy-MM-dd", "1979-02-12");

long age = routines.TalendDate.diffDate(routines.TalendDate.getCurrentDate(),myBirthday, "yyyy");

System.out.println(""+age);

This can be added to a routine  as follows....

 

public static long getAge(Date birthday, Date today){
      long returnVal = 0;

      if(birthday!=null&&today!=null){
             returnVal = routines.TalendDate.diffDate(today,myBirthday, "yyyy");
      }
      return returnVal;
}

The above routine method was written freehand, so you may want to tweak it first.

Anonymous
Not applicable
Author

Just i would like to know i put what exactly here in the variable please ??0683p000009M4iA.png

 

 

Anonymous
Not applicable
Author

Just i would like to know i put what exactly here in the variable please ??

Just i would like to know i put what exactly here in the variable please ??0683p000009M4iP.png

Anonymous
Not applicable
Author

@a_benlazreg 

 

I tried a slightly different method and results are as below.

 

The first value was 10-02-1980 in dd-mm-yyyy format

0683p000009M4jN.png

 

The next input value was 10-05-1980. Current date is 19-04-2019. So we have not reached the DoB for 2019 for this person and age should be 1 year less than previous sample.

0683p000009M4hi.png

 

Now the function used in tMap and it is as shown below.

0683p000009M4h3.png

 

TalendDate.diffDateFloor(TalendDate.getCurrentDate(),row1.dob,"yyyy") 

Hope your query is resolved by this method.

 

There are other diff date functions also available in Talend tMap. Please pick the function according to your specific requirement.

0683p000009M3oE.png

 

If the answer has helped you, please spend a second to mark the topic as resolved. Kudos are also welcome 🙂

 

Warm Regards,
Nikhil Thampi

Please appreciate our Talend community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved 🙂

 

Anonymous
Not applicable
Author

Thank you very much nikhilthampi. Your solution it worked well.

Cordially.