How to calculate age of the person based on dob(date and time) attribute

0
HOW TO CALCULATE AGE OF THE PERSON BASED ON DOB(DATE AND TIME) ATTRIBUTE USING LIST OPERATION?     for eg: I have List of employee data's, in that I have one attribute 'DOB'. so, based on DOB how to calculate employee age?   So that, I can easily delete employee details Age < 18. record must be deleted using list?    
asked
4 answers
1

Hello Nirosha N,

 

What you can do this is create some logic with a variable with a cutoffdateofbirth, this variable you can define by the following:

 

addYears([%CurrentDateTime%], -18)

 

more about this function here

https://docs.mendix.com/refguide/add-date-function-calls/

 

After you calculate this cutoff date you can retrieve the employees based on a xpath:

 

dateofbirth > cutofdateofbirth

 

Then you will get a list of all the employees that are younger than 18 and you can loop over this list to clean up the data

 

Hope this helps,

 

Good luck!

answered
2

Hi Nirosha,

Maybe you Can use 

calendarYearsBetween()

function, and calculate the years between the DOB and current date and then use it to check if it is bigger than 18 or not.

calendarYearsBetween(DOB,[%CurrentDateTime%])

This will return you the number of years.

You can read more about this using this URL

 

Let me know, if you have any issues,

Hope it helps!

Rishabh

(Resilient It Services)

answered
0

Screenshot 2024-07-03 151927.png

 

Check my flow is correct for delete the employee record if emp_age < 18 ? 

 

Note: here I'm not going to delete the record instead I'm just changing the attribute of is_delete = true.

answered
0

I have one query I have two Attributes DOB(Date and Time) and Age(Integer) 

 

then How you'll calculate the age for integer data type?

answered