Jump to content

Archived

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

jo.nova

Difference between dates?

Recommended Posts

How would I write a function to check if someone is a certain age?  They will be filling in a date of birth field, which I can check against today's date.  But how do I implement it?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites

×

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.