Hello guys,
How could I calculate an person's age if I have their year of birth?
Im trying this function:
But is not working at all... what I am doing wrong?
Using this code:
Is getting this:
Database screenshot: http://i.imgur.com/mjLrEQx.png
Waiting for your help, thanks
Thanks heaps
Tim
__________________
Added after 22 Hours 54 minutes:
Ok, a new try...
If I have this code to calculate age:
And If I have this one to get the birth date:
I need to replace the '04-08-1967' of 1st code with the 2nd code right?
But how can I do that? My php knowledge is very poor...
I tried:
But without success... Im doing something wrong... help
Thanks!!
How could I calculate an person's age if I have their year of birth?
Im trying this function:
PHP:
function age_in_years() {
global $postmeta;
$year_of_birth = get_field( "date_of_birth",$modelID);
$date1 = strval( $year_of_birth );
$date2 = strval( date( 'yy') );
$age = $date2 = $date1;
return $age;
}
But is not working at all... what I am doing wrong?
Using this code:
PHP:
<?php echo age_in_years();?>
Is getting this:
Code:
05/07/1992
Database screenshot: http://i.imgur.com/mjLrEQx.png
Waiting for your help, thanks
Thanks heaps
Tim
__________________
Added after 22 Hours 54 minutes:
Ok, a new try...
If I have this code to calculate age:
PHP:
<?php echo date_diff(date_create('04-08-1967'), date_create('today'))->y; ?>
And If I have this one to get the birth date:
PHP:
<?php echo get_field( "date_of_birth",$modelID); ?>
I need to replace the '04-08-1967' of 1st code with the 2nd code right?
But how can I do that? My php knowledge is very poor...
I tried:
PHP:
<?php echo date_diff(date_create('get_field( "date_of_birth",$modelID);'), date_create('today'))->y; ?>
But without success... Im doing something wrong... help
Thanks!!
Last edited: