Display user registration date

I want to show user registration date like

Member since: 15,dec 2012.

I have a code

<?php echo date("M Y", strtotime(get_userdata(get_current_user_id( ))->user_registered)); ?>

but it show same date in all users profiles. Can some one please tell me how I fix that.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

get_current_user_id() give you the user id of the logged in user. And that is: you.

You have to get all users:

<?php
        $users = get_users();

        foreach( $users as $user ) {

            $udata = get_userdata( $user->ID );

            $registered = $udata->user_registered;

            printf( '%s member since %s<br>', $udata->data->display_name, date( "M Y", strtotime( $registered ) ) );
        }

Method 2

$udata = get_userdata( $user->ID );
$registered = $udata->user_registered;
printf(
    $table,
    'Registered',
    date( "M Y", strtotime( $registered ) )
);

Method 3

If you want to use it for front-end, this is the best example:

//Get post author ID
$post_author_id = get_post_field( 'post_author', $post->ID );

//Get the registration date
$registered_date = get_the_author_meta( 'user_registered', $post_author_id );

//Convert to desired format
$output = date( 'F j, Y', strtotime($registered_date));

//Echo
echo $output;


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x