Php – How to calculate the age of a person in year, month, days in PHP?

PHP

Possible Duplicate:
How can I calculate the age of a person in year, month, days?

I want to calculate the age of a person given the date of birth and the current date in years, months and days relative to the current date.

For example:

>>> calculate_age(2008, 01, 01)
1 years, 0 months, 16 days

Best Answer

You can use PHP date_diff http://php.net/manual/en/function.date-diff.php or http://www.php.net/manual/en/datetime.diff.php to achieve what you want and you can output it in any format you want using PHP date format

$interval = date_diff(date_create(), date_create('2008-01-01 10:30:00'));
echo $interval->format("You are  %Y Year, %M Months, %d Days, %H Hours, %i Minutes, %s Seconds Old");

echo

You are 04 Year, 04 Months, 1 Days, 00 Hours, 56 Minutes, 36 Seconds Old