I store Date of Birth(DoB) in a mysql database from a html post form.
So if a user enter 1957-03-07 as his DoB, then it stores as 1957-03-07 00:00:00 in mysql database which field name is 'dob'.
Now I want to calculate age between current date and DoB by a php script.
So I execute following mysql query:
Code: Select all
$result = mysql_query("SELECT *,DATE_FORMAT(FROM_DAYS(DATEDIFF(NOW(),dob)), '%yy %mm %dd') AS age FROM $table WHERE user_name like '%$username%'") or die(mysql_error());
while($row=mysql_fetch_assoc($result)){
echo $row['age'];
}But the fetched output from the mysql query is showing age as 56years 01months 20days. I can correct days by deducting 1 in mysql query like this: ..........DATE_FORMAT(FROM_DAYS((DATEDIFF(NOW(),dob)-1)).......... but how about months?
Why it is adding 01 month with actual age?
How to eliminate this imperfection?
Best Regards