Convert DOB to Age
1
Cyber-Drugs
The below is an old bit of code I threw together when I was developing a Friend Networking site back in 2001. The site didn't last all that long, but I did manage to save all the handy snippets I used in it.
Below is code, which will return the age of somebody, when you parse their date of birth to it. I will probably make a cleaner version of the code at a later date and share it with everyone here.
Below is code, which will return the age of somebody, when you parse their date of birth to it. I will probably make a cleaner version of the code at a later date and share it with everyone here.
<?php
//
// Return user's age by entering in DOB
//
function getAge($date_d, $date_m, $date_y)
{
$today_d = date("d");
$today_m = date("m");
$today_y = date("Y");
if ($date_d <= $today_d)
{
$d_d = $today_d - $date_d;
}
if ($date_m <= $today_m)
{
$d_m = $today_m - $date_m;
}
if ($date_y <= $today_y)
{
$d_y = $today_y - $date_y;
}
$age = $d_y;
if ($d_m)
{
if ($d_m == "0")
{
if ($d_d)
{
$age = $age - 1;
}
}
} else {
$age = $age - 1;
}
return $age;
}
?>






There are currently no comments for this snippet.