[Resolved] Display age instead of date

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.

Our next available supporter will start replying to tickets in about 1.96 hours from now. Thank you for your understanding.

This topic contains 1 reply, has 2 voices.

Last updated by Minesh 2 years, 4 months ago.

Assigned support staff: Minesh.


Hi. I have created a date field in a CPT called WI Groups. When the user adds the birth day/year of a group, it is displayed as 'Founded 1996'. I need it to say (22) as in 22 years old. How can I create a database query and View which displays this?

<!-- wpv-loop-start -->
<table width="100%" class="wpv-loop js-wpv-loop">
<wpv-loop wrap="2" pad="true">
[wpv-item index=1]
[wpv-post-body view_template="Loop item in WI page list"]
[wpv-item index=other]
[wpv-post-body view_template="Loop item in WI page list"]
[wpv-item index=2]
[wpv-post-body view_template="Loop item in WI page list"]
[wpv-item index=pad]
[wpv-item index=pad-last]
<!-- wpv-loop-end -->
[wpml-string context="wpv-views"]No items found[/wpml-string]

Template for this View

[wpv-post-link] - Founded [types field='year-founded' style='text' format='Y'][/types]

Page where View output can be seen: hidden link



Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Well - as I understand, you want to subtract your year field value from the current year and display the difference as result - correct? If yes:

Please add following code to your current theme's functions.php file:

add_shortcode( 'calculate_year', 'func_calculate_year');
function time_ago_func($atts){
    global $wpdb;
    extract( shortcode_atts( array(
    'birthdate' => '',
    ), $atts ) );
      $age = floor((time() - $birthdate)/(365*24*60*60));
     return $age;

Call the above shortcode inside your Template  :

[wpv-post-link] - ( [calculate_year birthdate='[types field="year-founded" raw="true"][/types]'] )