PHP – YYYY-MM-DD to Years Old

 

<?php
$birthDate = "1984-05-21";

$birthDate = explode("-", $birthDate);

$age = (date("md", date("U", mktime(0, 0, 0, $birthDate[2], $birthDate[1], $birthDate[0]))) > date("md") ? ((date("Y")-$birthDate[0])-1):(date("Y")-$birthDate[0]));
echo "Age is: ".$age;
?>

 

As seen on http://stackoverflow.com/questions/15341767/calculate-age-with-php-in-yyyy-mm-dd-format

 

Leave a Reply

Your email address will not be published. Required fields are marked *

*