Home Forums General Issues Calculate age and add to field


Calculate age and add to field

  • I’ve seen the following code promoted to calculate age from a DOB entry. But where does the code have to be installed, is it functions.php? And how would I save the output of this code to a ACF titled “age”? I don’t need it to appear on the screen – just saved backend, so can the echo below be deleted?
    $date = get_field(‘date_of_birth’);
    $birthday = new DateTime($date);
    $interval = $birthday->diff(new DateTime);
    echo $interval->y.’ years old’;

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.