Check The Date Condition like Date occurs after 30 days in If condition in JSON | Community
Skip to main content
Level 2
April 13, 2023
Solved

Check The Date Condition like Date occurs after 30 days in If condition in JSON

  • April 13, 2023
  • 2 replies
  • 941 views

We are trying to find the right Json where check the date occurs less or greater then xx days after today. please find the below sample. Birthdate has the year init. Do we have any other option to crack this?

 

{%#if profile.person.birthDate occurs <=30 days after today%} {"content_id":"sample": "{{profile.person.name.firstName}}"} {%/if%}

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by akshaaga

@pandiyarajanra1 ,

To compare dates in JSON & to check if the birthdate occurs less or greater than xx days after today, you can use-

{% if moment(profile.person.birthDate).diff(moment(), 'days') <= 30 %}

  {"content_id": "sample", "name": "{{profile.person.name.firstName}}"}

{% endif %}

In the above, moment(profile.person.birthDate) creates a moment object from the birthdate, and moment() creates a moment object for the current time. The diff method calculates the difference in days between the two moments. If the difference is less than or equal to 30, the JSON object is output with the person's first name.

Note that you may need to adjust the syntax and formatting depending on the specific JSON library or template engine you are using.

 

2 replies

SatheeskannaK
Community Advisor
Community Advisor
April 20, 2023

Can you try this to see if that works,

 

{%#if (profile.person.birthDate.getDayOfYear() - now.getDayOfYear() <= 30) and (profile.person.birthDate.getDayOfYear() - now.getDayOfYear() >= 0) %}

{{profile.person.name.lastName}}

{%/if%}

Thanks, Sathees
akshaaga
Adobe Employee
akshaagaAdobe EmployeeAccepted solution
Adobe Employee
April 26, 2023

@pandiyarajanra1 ,

To compare dates in JSON & to check if the birthdate occurs less or greater than xx days after today, you can use-

{% if moment(profile.person.birthDate).diff(moment(), 'days') <= 30 %}

  {"content_id": "sample", "name": "{{profile.person.name.firstName}}"}

{% endif %}

In the above, moment(profile.person.birthDate) creates a moment object from the birthdate, and moment() creates a moment object for the current time. The diff method calculates the difference in days between the two moments. If the difference is less than or equal to 30, the JSON object is output with the person's first name.

Note that you may need to adjust the syntax and formatting depending on the specific JSON library or template engine you are using.