开发者

PHP: How to calculate person's age in months+days?

开发者 https://www.devze.com 2023-01-08 15:52 出处:网络
I want to calculate person\'s age in months plus da开发者_C百科ys using date of birth (example: 1986-08-23).

I want to calculate person's age in months plus da开发者_C百科ys using date of birth (example: 1986-08-23).

For example:

0 months and 25 days old.
5 months and 20 days old.
150 months and 4 days old.
285 months and 30 days old.

Any Idea? Thanks.


$date = new DateTime('1990-10-13');
$diff = $date->diff(new DateTime());
printf("%d months and %d days old", $diff->y*12 + $diff->m, $diff->d);

Note that DateTime::diff() requires PHP 5.3.0 or higher.

0

精彩评论

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