I’m building a registration system with PHP and need to create a function that takes a date of birth (as a timestamp) and returns the age on (April 31). What I have now is:
<?php
function get_adj_age($dob)
{
$age = (time()-$dob);
$today = strtotime(date('F d', time()));
$diff = ($cutoff - $today);
$adj_age = floor(($age+$diff)/31556926);
return $adj_age;
}
For some reason this is breaking my brain. Anyone mind checking me on this? Cheers.
Essentially what this does it create a DateTime object for April 31st of the current year and then subtracts the date the person was born. This results in a DateInterval from which the year is retrieved and returned.