Jump to content

[SOLVED] work out age given a year


jesushax

Recommended Posts

You will find that will only work when the birthday has already occured in the current year. You must subtract 1 if the birthday has not already occured in the current year -

 

<?php
$date = '1985-04-14'; // standard yyyy-mm-dd format
$today = date("Y-m-d");
$age = substr($today, 0, 4) - substr($date, 0, 4) - (substr($today, 5,5) < substr($date, 5,5));
echo "DOB: $date, Age: $age<br />";
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.