i have a script for determining a users date of birth. i feed the date of birth of a user, then convert this into a unix timestamp. i then compare this date against the unix timestamp for the current date. i then divided the two dates which gives me the age of the user. it not a hundred percent accurate becuase it does not take into account Leap years, however its good enough for my purposes.
the problem i have is when it comes to converting this script into a function. i am having problems converting the users DOB into a timestamp. it might be easier at this point if i show you the problem.
Code: Select all
//THE DOB FUCTION
//I FEED THE FUCNTION 3 PARAMETRES I.E THE DOB OF USER: 6 , 17, 1989
function bithday2 ( $timestamp1, $timestamp2, $timestamp3 )
{
// I then attempt to convert teh dates into a UNIX Time Stamp. ( i place 0,0,0 at the front of the converion-i did this buecase
//a unix timestamp need 6 parametres THEN ATTETHEN AI THEN
$TIMESTAMP = " 0,0,0, $timestamp1. , .$timestamp2 . , .$timestamp3" ;
$ageTime = mktime( $TIMESTAMP ); // Get the TIMESTAMP for the birthday
$t = time(); // Store current time for consistency
$age = ($ageTime < 0) ? ( $t + ($ageTime * -1) ) : $t - $ageTime;
$year = 60 * 60 * 24 * 365;
$ageYears = $age / $year;
$birthdate = floor($ageYears) ;
return $birthdate;
}
echo bithday2 ( 06 , 17, 1989 );
Notice: A non well formed numeric value encountered in C:\wamp\www\aupair-world-agency.com\cms\sql_fns.php on line 110
i have obviosuly not done the concanternation properly. i am not sure how to place the ( , )' comma , between teh variables . however. apart from this problem the script does indeed work. i enclose below a copy of the script (outside of the fuction. you will note, if you test it, that it does indeed work.
so where have i gone wrong. thanks everyone for your kind help
Code: Select all
function bithday ( )
{
$ageTime = mktime(0,0,0, 06 ,17 , 1982 ); // Get the person's birthday timestamp
$t = time(); // Store current time for consistency
$age = ($ageTime < 0) ? ( $t + ($ageTime * -1) ) : $t - $ageTime;
$year = 60 * 60 * 24 * 365;
$ageYears = $age / $year;
$birthdate = floor($ageYears) ;
return $birthdate;
}
echo bithday ( );