I have a date of birth field and I need to learn how to create a way to calculate the persons age and display it in a post.
I would imagine have the date of birth date picker field is obvious, but to I need to create another field like “age” where the calculated age can be output?
Thank you for any suggestions
You don’t need a separate age field. You can do the calculation in the theme itself. Something like:
<?php $DOB = get_field('date_of_birth'); // change for field name
$birthday = new DateTime($DOB);
$dateDiff = $birthday->diff(new DateTime);
echo $dateDiff->y.' years old';
?>