FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


DOB -> Age





DanielXP
I need a script that can change

$DD
$MM
$YYYY

as the DOB to there current age.


Thanks
Daniel
MrBlueSky
Something like this:

Code:

<?php

$MM = 1;
$DD= 1;
$YYYY = 1988;

$bDay = mktime ( 0, 0, 0, $MM, $DD, $YYYY );
$cTime = time ();
$age = $cTime-$bDay;
$yr = floor ( $age/(60*60*24*356.25) );
print "You are $yr years old";


?>


But you probably have to tweak it a bit
DanielXP
DOB

11/04/1991

shows 16 not 15

how can i make it so if its before the time u have to remove a year
hexkid
Code:
<?php
function calculate_age($y, $m, $d) {
  $guess_age = date('Y') - $y;
  $guess_time = mktime(0, 0, 0, $m, $d, $y + $guess_age);
  if ($guess_time > time()) {
    $age = $guess_age - 1;
  } else {
    $age = $guess_age;
  }
  return $age;
}

$YYYY = 2002;
$MM = 1;
$DD = 28;
$age = calculate_age($YYYY, $MM, $DD);
echo "You are $age years old.<br>\n";
?>
DanielXP
Thanks hex.
duckling
using explode() would be more useful.

Code:
$birthday = "01-17-1988";
$var = explode("-", $birthday);


then, you can use:

$var["0"] as day,
$var["1"] as month,
$var["2"] as year Smile
kv
duckling wrote:


then, you can use:

$var["0"] as day,
$var["1"] as month,
$var["2"] as year Smile


var is a reserved word in PHP
Related topics
Favourite game? (OFFICIAL THREAD)
Starcraft vs. Age of Empires II
Qual o melhor Game na opiniao de vcs????
Help, I can't post an HTML signature!!!
HTML signatures!!!
Including Rank
How do I send a webform?
Css- 2 equal columns in Explorer
Making a space in C++?
BBcode Problem implementing??
Do you actually finish games?
Help with php email
Application form - getting rid of ucwords
Application form - onSubmit='return false;
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.