Converting date-output to year-count (age) - Joomla 2.5/JomSocial 2.4.2


#1

Hi,

I´m running Joomla 2.5 with JomSocial 2.4.2

I´m trying to manually add an “age”-field to the profile page om my site.
The file I´m editing is: profile.header.php

I have managed to get the field-info from all the users custom fields to show the right place. The only problem I have is that the birthday-field only shows the date of birth. I want it to show the age…

This is my code I made, to get the info from the user custom field, “FIELD_BIRTHDATE”:

<?php $jspath = JPATH_BASE.DS.'components'.DS.'com_community'; include_once($jspath.DS.'libraries'.DS.'core.php'); $data7 = $user->getInfo('FIELD_BIRTHDATE'); echo '

Age: '.$data7.'

'; ?>

On the site the result is like this example: Age: 1981-3-12 23:59:59

Now, does anyone know what I need to do change the output from showing YYYY-MM-DDD to an actual age in years?

Brgds


#2

To put it in pseudocode.

AGE = NOW - BIRTHDATE; ( the difference between the birthdate and now ) // in years AGEyears = intval( (NOWin_seconds_since_1970 - BIRTHDATEin_seconds_since_1970)/seconds_per_year)

To get to the seconds since 1970 (EPOCH) you can use the mktime() function.

good luck,
O.