0 votes
in Rock by DavidTurner (14.9k points)
edited

Would like to display child's age (in yrs) on check-in label but if they are younger than 3 show it in yrs and months, and if they are less then 2 months, show age in weeks, and if less than 3 weeks, show age in days.

This is similar to the HumanizeTimSpan lava filter, but it can't quite be configured to show age in this format.

1 Answer

0 votes
by DavidTurner (14.9k points)
edited
 
Best answer

The Lava below will show age based on those parameters:

{% assign years = Person.Age %}
{% assign months = Person.BirthDate | DateAdd:years,'y' | DateDiff:'Now','M' %}
{% assign weeks = Person.BirthDate | DateAdd:years,'y' | DateDiff:'Now','d' | DividedBy:7 | Floor %}
{% assign days = Person.BirthDate | DateAdd:years,'y' | DateDiff:'Now','d' %}

{% if years == 0 and months == 0 and weeks <= 2 %}
    {{ 'day' | ToQuantity:days }}
{% elseif years == 0 and months < 2 %}
    {{ 'wk' | ToQuantity:weeks }}
{% elseif years == 0 %}
    {{ 'mo' | ToQuantity:months }}
{% elseif years >= 3 %}
    {{ 'yr' | ToQuantity:years }}
{% else %}
    {{ 'yr' | ToQuantity:years }}, {{ 'mo' | ToQuantity:months }}
{% endif %}
Welcome! Here you can ask questions and receive answers (hopefully) from other members of our team.
...