In case any one else finds this and is having issues, there is a missing quotation mark in this line:
echo '<img src="' . $image . ' />'; //change depending on the return value of the image field
should be
echo '<img src="' . $image . '" />'; //change depending on the return value of the image field
This one worked for me!
<?php
$date = get_field('date_of_birth');
$birthday = new DateTime($date);
$interval = $birthday->diff(new DateTime);
echo $interval->y.' years old';
?>
This one:
<?php
//date in mm/dd/yyyy format; or it can be in other formats as well
$birthDate = get_field('date_of_birth');
//explode the date to get month, day and year
$birthDate = explode("/", $birthDate);
//get age from date or birthdate
$age = (date("md", date("U", mktime(0, 0, 0, $birthDate[0], $birthDate[1], $birthDate[2]))) > date("md")
? ((date("Y") - $birthDate[2]))
: (date("Y") - $birthDate[2]));
echo "Age:" . $age;
?>
For some reason generated the current year. But no matter, I have it all working now, thanks!
Thanks, I will give these a try! I was going to use a date picker, in answer to the first question.
Ok, thanks! I will give it a shot.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.