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.