开发者

subtract two dates in php [duplicate]

开发者 https://www.devze.com 2023-04-09 04:43 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicate: PHP calculate age I\'m trying to subtract the years and check the user\'s age. I keep getting 1969 for $use
This question already has answers here: Closed 11 years ago.

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 />";
e开发者_高级运维cho $today_date-$user_birth;

Any ideas?


$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.

0

精彩评论

暂无评论...
验证码 换一张
取 消