Skip Navigation

[Resolved] Display Age from Date of Birth Input

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 7 replies, has 2 voices.

Last updated by Minesh 10 months ago.

Assisted by: Minesh.

Author
Posts
#2690386

I want to have a form field that asks for a date of birth and then displays the calculated age on a post in the front end.

Thanks for any assistance.

#2690468

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

I would like to know how exactly you want to display the age?

You want to display age with only Years or years with Months and number of days?

#2690595

Thanks for the response.

We only need the age in years to display. So just the number value.

Thanks

#2690727

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

To display the age based on the custom date field we have to calculate the age and for that we will require custom shortcode.

You can add the following custom shortcode to "Custom Code" section offered by Toolset:
- https://toolset.com/documentation/programmer-reference/adding-custom-code/using-toolset-to-add-custom-code/#adding-custom-php-code-using-toolset

For example:

add_shortcode( 'calculate_age', 'func_calculate_age_from_date_field');
function func_calculate_age_from_date_field($atts){
    $age = 0;
    extract( shortcode_atts( array(
    'field' => '',
    ), $atts ) );
 
     $age = floor( (time() - $field) /(365*24*60*60));
     return $age;
}

And you can call the above shortcode as given under:

[calculate_age field='[types field="birthdate" output="raw"][/types]']

Where:
- Replace "birthdate" with your original field slug.

#2690909

Thank you for the information. I cannot implement it right now, but will as soon as I figure out how to use toolset. I'm having way too many issues making it work. Seems to easy in the videos but nothing works on our site as it's seen in the videos.

We will keep trying and thank you so much for your help.

Law

#2691028

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

If you would like to understand how Toolset works - you can use the course we offer:
- https://toolset.com/course/

In addition to that - you can also use our free test platform http://www.discover-wp.com and try to use use any of the reference site we offer:
- https://discover-wp.com/site-templates/

All sites are build on top using Toolset and you can create a test site of your choice and play with it that will help you to understand many things hopefully.

#2691673

Our biggest issue is, we have a directory we created a long time ago and simply want to use the same post data and fields with toolset. I can't see a way of doing that since we never used custom post types in the past, not part of the data we have stored in the database.

We have 491 records that we need to simply import into toolset and map the existing fields so we can use the data, enter new data, etc.

Is this possible?

Thanks

#2691993

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

As per our support policy - we entertain only one question per ticket. This will help other users searching on the forum as well as help us to write correct problem resolution summery.

The ticket was originally reported to as solution for display age based on the birthdata and its already been shared. May I kindly ask you to open a new ticket with every new question you may have with all the required details.

You're welcome to mark resolve this ticket.