XPath for birthdays

3
Hi, I'm new to xpath and mendix, I've written a few basic constraints however I could do with some assistance. I need to create a datagrid to show only the customers that will be turning 18 that year. My Customer entity has a D.O.B Date and time attribute and also an age attribute that is calculated by microflow. My original thought was to calculate how many weeks in 18 years (approx 938) and have the xpath calculate which customers would reach that many weeks in the current year. Thank you, Christina
asked
4 answers
3

You could solve this in XPath with the following constraint:

[Geboortedatum >=  '[%BeginOfCurrentYearUTC%] -  18 * [%YearLength%]']    
[Geboortedatum <=  '[%EndOfCurrentYearUTC%] - 18 * [%YearLength%]']

See this page for a reference.

answered
2

Seeing as you calculate the age with a microflow, can't you just also calculate (in the same microflow) if said person ''Turns 18 this year y/n'' and then just xpath on this boolean?

answered
1

You need to have a datasource microflow for your datagrid. In that microflow you can determine what year it is with a token '[%CurrentDateTime%]'.

Substract 18 years from that and you know in which year the Customers would have to have their birthdate in. Knowing that you can do a retrieve with the following XPath: 'year-from-datetime($Attribute)'

For example. This year is 2015. So everyone born in 1997 is or will turn 18 this year

Your XPath would be something like: [year-from-datetime($Customer/DateOfBirth = 1997]

I did this from the top of my head, so please bear with me :-)

Obviously there are a lot of ways to get the results you want. This could be one of them..

Refguide for XPath year from datetime

Refguide for XPath constraints

answered
0

You can use the xpath functions year-from-dateTime(). This will give you the year of the date value. After this you can substract by 18 and compare or the another XPATH operation.

answered