Jump to content

Difference between dates?


jo.nova

Recommended Posts

Subtract the year of birth from this year to get age. However then check if month/day of birthdate has been reached this year, If not, subtract 1 from age

eg if born in 1990 thenthey will be 16 this year. But if birthday is November and it's now September then age is still 15.
A quick example... (you still need to validate the date!)

[code=php:0]<?

function get_age ( $m, $d, $y )
{
$bd = date ( 'U', strtotime ( $m . '/'. $d . '/' . $y ) );
$yo = date ( 'Y', time () ) - date ( 'Y', $bd );

if ( date ( 'z', time () ) < date ( 'z', $bd ) )
{
$yo -= 1;
}

return ( $yo );
}

$month = 10;
$day = 28;
$year = 1985;

echo get_age ( $month, $day, $year );

?>[/code]



me!

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.