Expand my Community achievements bar.

Join us on September 25th for a must-attend webinar featuring Adobe Experience Maker winner Anish Raul. Discover how leading enterprises are adopting AI into their workflows securely, responsibly, and at scale.
SOLVED

Compare birth date if it is x years old in Expression editor in Condition

Avatar

Level 2

Hi AJO experts, 
I would like to see birthdate is equal to 59 years old and 60 and 65. How can I do it in Expression editor in AJO condition.

{%= ageInMonths(#{ExperiencePlatform.ProfileFieldGroup.profile.person.birthDate}) >= 714 %}

It is not working.


Please suggest.

Kind regards,

Vidhi

1 Accepted Solution

Avatar

Correct answer by
Employee Advisor

@VidhiKh1 By slightly tweaking the above logic as follows, yes

(
    (
      ((toInteger(substr(toString(now()),0,4))) * 12 + (toInteger(substr(toString(now()),5,7))))
      -
      ((toInteger(substr(toString(#{ExperiencePlatform.ProfileFieldGroup.profile.person.birthDate}),0,4))) * 12
       + (toInteger(substr(toString(#{ExperiencePlatform.ProfileFieldGroup.profile.person.birthDate}),5,7))))
    ) / 12 == 59
  ) 
  or 
  (
    (
      ((toInteger(substr(toString(now()),0,4))) * 12 + (toInteger(substr(toString(now()),5,7))))
      -
      ((toInteger(substr(toString(#{ExperiencePlatform.ProfileFieldGroup.profile.person.birthDate}),0,4))) * 12
       + (toInteger(substr(toString(#{ExperiencePlatform.ProfileFieldGroup.profile.person.birthDate}),5,7))))
    ) / 12 == 59.5
  ) 

View solution in original post

12 Replies

Avatar

Employee Advisor

Kindly use the following expression 

Age -> {%= toInt((ageInMonths(toDateTimeOnly(profile.person.birthDate))/ 12)) %} 

{%# if  toInt((ageInMonths(toDateTimeOnly(profile.person.birthDate))/ 12))  = 59
  or toInt((ageInMonths(toDateTimeOnly(profile.person.birthDate))/ 12))  = 60
  or toInt((ageInMonths(toDateTimeOnly(profile.person.birthDate))/ 12)) = 65 %}
  Display Relevant Content
{%else%}
  Fallback
{%/if%}

Avatar

Employee Advisor

@VidhiKh1 try this

(
  yearsBetween(now(), profile.person.birthDate) == 59
  ||
  yearsBetween(now(), profile.person.birthDate) == 60
  ||
  yearsBetween(now(), profile.person.birthDate) == 65
)

Avatar

Level 2

Hi these solutions are not working in expression editor: I get error that it is invalid.

 

VidhiKh1_0-1757663364590.png

 

Avatar

Employee Advisor

Previous example I shared was with respect to personalization editor. You can adapt your condition by looking at the example mentioned here https://experienceleaguecommunities.adobe.com/t5/journey-optimizer-questions/getting-age-field/m-p/6... 

 



(
  (
    (toInteger(substr(toString(now()),0,4))) -
    (toInteger(substr(toString(#{ExperiencePlatform.ProfileFieldGroup.profile.person.birthDate}),0,4)))
  ) == 59
)
or
(
  (
    (toInteger(substr(toString(now()),0,4))) -
      (toInteger(substr(toString(#{ExperiencePlatform.ProfileFieldGroup.profile.person.birthDate}),0,4)))
  ) == 60
)
or
(
  (
    (toInteger(substr(toString(now()),0,4))) -
      (toInteger(substr(toString(#{ExperiencePlatform.ProfileFieldGroup.profile.person.birthDate}),0,4)))
  ) == 65
)

Avatar

Employee Advisor

@VidhiKh1 In the advanced expression editor you can compare age in years directly with the age() helper, then combine the three values with OR logic:

(age(#{ExperiencePlatform.ProfileFieldGroup.profile.person.birthDate}) = 59
 or age(#{ExperiencePlatform.ProfileFieldGroup.profile.person.birthDate}) = 60
 or age(#{ExperiencePlatform.ProfileFieldGroup.profile.person.birthDate}) = 65)

• age(date) returns the number of whole years between now and the date you pass (it already handles leap years for you).
• The = operator checks for equality, and the or operator lets any of the three comparisons pass.If you prefer a more compact form you can use the in() collection operator:

in([59,60,65], age(#{ExperiencePlatform.ProfileFieldGroup.profile.person.birthDate}))

Avatar

Employee Advisor

@VidhiKh1 did you try the suggestions? 

Avatar

Level 2

Hi,
Thank you for your inputs. Unfortunately, it didn't help and gave me the below error:

VidhiKh1_0-1757904129524.png


Kind regards,

Vidhi



Avatar

Employee Advisor

@VidhiKh1 Kindly use the expression I shared earlier as age function isn't available in advanced expression editor.

Avatar

Level 2

Hi Mohan,

Apologies, yeap I will try it now and let you know by end of day if it is working.
Good thing editor isn't giving any errors But I just need to test it to ensure that it is working.

 

Kind regards,

Vidhi

Avatar

Level 2

Also @Mohan_Dugganab : Would you know if I need to check for 59.5 years age then the same logic will work?

 

Kind regards,

Vidhi

Avatar

Correct answer by
Employee Advisor

@VidhiKh1 By slightly tweaking the above logic as follows, yes

(
    (
      ((toInteger(substr(toString(now()),0,4))) * 12 + (toInteger(substr(toString(now()),5,7))))
      -
      ((toInteger(substr(toString(#{ExperiencePlatform.ProfileFieldGroup.profile.person.birthDate}),0,4))) * 12
       + (toInteger(substr(toString(#{ExperiencePlatform.ProfileFieldGroup.profile.person.birthDate}),5,7))))
    ) / 12 == 59
  ) 
  or 
  (
    (
      ((toInteger(substr(toString(now()),0,4))) * 12 + (toInteger(substr(toString(now()),5,7))))
      -
      ((toInteger(substr(toString(#{ExperiencePlatform.ProfileFieldGroup.profile.person.birthDate}),0,4))) * 12
       + (toInteger(substr(toString(#{ExperiencePlatform.ProfileFieldGroup.profile.person.birthDate}),5,7))))
    ) / 12 == 59.5
  ) 

Avatar

Level 2

Thank you @Mohan_Dugganab ,
Your solution is really helpful! Appreciate it!

 

Kind regards,

Vidhi