...

View Full Version : Date calculation



MatesOnline
09-24-2004, 12:44 PM
Hi everyone

ok for most of you this will be very easy lol

i have a registration form on my site and i have 3 drop down menu's
day , mon , year each containing 2 digit numbers


what i would like to do .. is when they submit the form
the page will automatically determin their age based on the selections from day , mon , year

sounds easy huh? lol

any help will be appreciated

raf
09-24-2004, 01:54 PM
indeed very easy. but instead of spending time reinventing this sort of things, i always just run a search at www.php.net and there are plenty of premade scripts like this one


/*chris dot shepherd at gmail dot com
27-Aug-2004 05:59
A nice way to calc age seeing that mktime only goes back until 1970 is to use the date function like this... */

<?php
//Find the difference in year, month, and day
$yeardiff = date("Y") - $dobyear;
$monthdiff = date("m") - $dobmonth;
$daydiff = date("j") - $dobday;

/*
* if month or day is negative we have yet to reach it so
* we need to subtract a year seeing we haven't
* reached our birthday yet, else yeardiff is correct
*/

if ($monthdiff <= 0 && $daydiff < 0) {
$age = $yeardiff - 1;
} else {
$age = $yeardiff;
}

echo $age;
?>

on http://www.php.net/date

MatesOnline
09-24-2004, 01:58 PM
ahh

perfect.

Thanks :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum