0

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.

1 Answer 1

0

Just 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');
            }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.