自定义字段+年龄计算器显示年份和月份[关闭]

I have a custom field name "date_of_birth" on my custom post type which is in [Ymd] format on my database. Now, I want to compare that date of birth to current time and want to display "You are # years # months."

I am able to calculate Years only but it is not accurate. Help me.

You can use date_diff() function:

<?php

$diff = date_diff(date_create(), date_create('19951125'));
echo $diff->format("You are %Y Years and %M Months.");