I want to display the age in years months and days in Wordpress post given the date of birth in the post. Suppose my date of birth is 14-Sep-1984, so as of today my age is 36 years 7 months 28 days. I tried the following code, but it only displays the years.
What I have tried:
function get_age_shortcode( $atts, $content = null ) {
extract( shortcode_atts( array(
), $atts ) );
$date = new DateTime($content);
$now = new DateTime();
$interval = $now->diff($date);
return (' Your age : %d years, %d month, %d days', $interval->y, $interval->m, $interval->d);
}
add_shortcode( 'get_age', 'get_age_shortcode' );
add_filter('widget_text', 'do_shortcode');