What you could do is something along the lines of this:
Table Structure:
userid - int (10) auto_increment primary key,
username - varchar (50),
userdob - varchar (25),
// Any Other Fields...
Store the userbirthday in this format:
dd month YYYY (Eg: 10 April 1970, 03 December 1986, etc...)
Now, using php you could take that string and turn it into timestamp using strtotime(), eg:
//....
$userBirthday = "29 December 1987"; // Eg: This variable may equal 10 April 1970, You WOuld get it from the DB, eg: $user['userdob']
$explode = explode(" ", $userBirthday); // Break it down into the day, month and year
$birthDay = $explode[0];
$birthMonth = $explode[1];
$birthYear = $explode[2];
//Now we can add the birthDay, birthMonth and this year (eg: 29 December 2010) to make a timestamp and find out exactly when their birthday is this year
$birthString = "".$birthDay." ".$birthMonth." ".date('Y');
$birthTimestamp = strtotime($birthString);
// Next we can compare it to the current timestamp to see if they have already had their birthday this year, because if they have then there's no point continuing, they will just have to wait until next year
$now = time(); // Current Timestamp
if($birthTimestamp > $now)
{
// Okay Let's Continue
// It's worth noting that this is a very basic example, so in reality you would want to actually check more throughly, eg: Okay their birthday may not be in the future, but what if it only happened a few hours ago? So what if it is their birthday today? This example would ignore that and only continue if their birthday is still yet to happen
// Okay so we know their birthday hasn't happened yet, so can we find out when it is?
$difference = $birthTimestamp - $now; // The time left between now and their birthday - In Seconds
// You could then break this $difference down into minutes, hours, days, weeks, months etc.. eg:
$type = 'Seconds';
$difference = $difference / 60; // This is now the time in minutes until their birthday
$type = 'Minutes';
$difference = $difference / 60; // Hours
$type = 'Hours';
$difference = $difference / 24; // Days
$type = 'Days';
$difference = $difference * 0.14285; // Weeks
$type = 'Weeks';
$difference = $difference * 0.22998; // Months
$type = 'Months';
$difference = round($difference, 2);
/******************************************************************************************************
* You will notice that the maths above is pretty crap, you may want to do it...well...unlike me...
******************************************************************************************************/
// Etc...
// Again you'll want to do it more thoroughly though, eg: Checking if there is at least 1 hours left before converting to hours, otherwise you'll end up with it being "0" or "0.n" if you round() it
// SO you could then simply display that if you wanted to, something like
$newAge = date('Y') - $birthYear;
echo "There is " . $difference . " " . $type . " left until your birthday. You will be ".$newAge." years old!<br>";
// Or you could do more checks, eg: you could display it only on round occasions, eg: 2 Months, 1 Month, 3 Weeks, 2 Weeks, 1 Week, etc... whatever you want really
}
//....