Calculating a person's age based on a date field

Ever wanted to calculate someone else's age based on a date field? That's possible using the [gv_age] shortcode.

Shortcode Parameters

The [gv_age] shortcode requires two parameters to calculate age.

  • entry_id - The ID of the entry for the age calculation. Can use the {entry_id} Merge Tag or a numeric entry ID.
  • field_id - The ID of the date field where date of birth is stored.

Example

This shortcode will calculate ages for all entries. Date of birth is stored in a date field with an ID of 44:

[gv_age entry_id="{entry_id}" field_id="44" /]

Adding the [gv_age] shortcode to a Custom Content field:

Entering the [gv_age] shortcode into the Options screen of a Custom Content field

The output:

The Multiple Entries View after adding the [gv_age] shortcode to a Custom Content field

Now that we have the age displaying, we can enter a label for the Custom Content field:

Adding a label to a Custom Content field containing the [gv_age} shortcodeAnd voilá:

The Multiple Entries View displaying a custom label for the [gv_age] Custom Content field

You'll need this code in order to enable the [gv_age] shortcode:

Related:  Where do I add the code samples you share?

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.