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%}
Solved! Go to Solution.
Views
Replies
Total Likes
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.
Views
Replies
Total Likes
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%}
Views
Replies
Total Likes
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.
Views
Replies
Total Likes