Working out DOB....

Links for php scripts

Moderators: macek, egami, gesf

crsk
New php-forum User
New php-forum User
Posts: 6
Joined: Tue Aug 05, 2003 12:28 am
Contact:

Working out DOB....

Postby crsk » Tue Aug 05, 2003 12:32 am

Right can any of you guys spot a mistake.. or perhaps have a better way of doing it.. my current code is:-

<?
mysql_select_db( "phptest" ) or die( mysql_error() );

// get the data from mysql
$result = mysql_query( "SELECT FirstName, DOB FROM test;" );
// set the current dates
$current_day = date("d");
$current_month = date("m");
$current_year = date("Y");
while ($myrow = mysql_fetch_row($result)) {
$name = $myrow[0];
$birthday = $myrow[1];

// set the dob dates
$dob_day = substr($birthday,6,2);
$dob_month = substr($birthday,4,2);
$dob_year = substr($birthday,0,4);
// calculate age
$age = ($current_year - $dob_year) - 1;
if ($dob_month < $current_month) { $age++; }
if ((
// calculate age
$age = ($current_year - $dob_year) - 1;
if ($dob_month < $current_month) { $age++; }
if (($dob_month == $current_month) && ($dob_day <= $current_day)) { $age++; }
print "Age = $age";
}
// finished!
?>

any help would be much appriciated..

sigix
php-forum Active User
php-forum Active User
Posts: 364
Joined: Mon Jul 14, 2003 9:39 pm
Location: /Earth/Xion

Postby sigix » Tue Aug 05, 2003 1:14 am

better read date functions from php.net will make life easy :!:


Return to “PHP Scripts”

Who is online

Users browsing this forum: No registered users and 0 guests

cron