
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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:
Thank you very much.
Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I tried a slightly different method and results are as below.
The first value was 10-02-1980 in dd-mm-yyyy format
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.
Now the function used in tMap and it is as shown below.
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.
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 🙂

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Just i would like to know i put what exactly here in the variable please ??

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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 ??

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I tried a slightly different method and results are as below.
The first value was 10-02-1980 in dd-mm-yyyy format
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.
Now the function used in tMap and it is as shown below.
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.
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 🙂

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you very much nikhilthampi. Your solution it worked well.
Cordially.
