I would like to add to the user profile the time from registration to the current day in the format:
With us: 7 years 3 months 2 weeks 6 days
OR
With us: 1 year 1 month 1 week 1 day
Me a bit helped this post Count days from registration date to today, but there countdown goes only in days.
I would like to add to the user profile the time from registration to the current day in the format:
With us: 7 years 3 months 2 weeks 6 days
OR
With us: 1 year 1 month 1 week 1 day
Me a bit helped this post Count days from registration date to today, but there countdown goes only in days.
Share Improve this question asked Sep 21, 2019 at 19:27 cogorihawcogorihaw 11 Answer
Reset to default 0Just gave an example of how to do it:
$today_date = new DateTime( date( 'Y-m-d', strtotime( 'today' ) ) );
$register_date = get_the_author_meta( 'user_registered', get_current_user_id() );
$registered = new DateTime( date( 'Y-m-d', strtotime( $register_date ) ) );
$interval_date = $today_date->diff( $registered );
if( $interval_date->days < 31 ) {
echo 'With us ' . $interval_date->format('%d days');
}
elseif( $interval_date->days < 365 ) {
echo 'With us ' . $interval_date->format('%m months %d days');
}
elseif( $interval_date->days > 365 ) {
echo 'With us ' . $interval_date->format('%y years %m month %d days');
}