-1

Possible Duplicate:
PHP calculate age

I'm trying to subtract the years and check the user's age. I keep getting 1969 for $user_birth, which I think the raw date can't be parsed.

$raw_birth = "01-19-1980";
$user_birth = date("Y", strtotime($raw_birth));
$today_date = date("Y", time());

echo $raw_birth."<br />".$today_date."<br />".$user_birth."<br />";
echo $today_date-$user_birth;

Any ideas?

Community
  • 1
  • 1
user962449
  • 3,743
  • 9
  • 38
  • 53

1 Answers1

1
$year="1997";
$month="01";
$day="24";

$age=date("Y");
$age-= $year;
if(($month>=date("m")) && ($day>date("d"))) {
    $age--;
}

This code calculates an accurate age of an user.

Remc4
  • 1,044
  • 2
  • 12
  • 24