12

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.

2

3 Answers 3

19

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 ) ) );
        }
6
  • but they show all user registration date, i want to show every member profile page with his joining date. please provide me.
    – Maan
    Commented Jan 1, 2013 at 13:06
  • 2
    gist.github.com/4427538
    – Ralf912
    Commented Jan 1, 2013 at 13:36
  • @Ralf912 Where exactly do we get to place your code? Thanks. Commented Jan 1, 2013 at 15:35
  • functions.php or plugin. wherelse? because it is not theme specific, a plugin would be the best place.
    – Ralf912
    Commented Jan 1, 2013 at 16:13
  • @Ralf912. On a multisite, can we just use the above code as a drop-in plugin (no plugin headers) so it can be independent from all themes and auto-activated for all sites? Commented Jan 4, 2013 at 13:12
2
$udata = get_userdata( $user->ID );
$registered = $udata->user_registered;
printf(
    $table,
    'Registered',
    date( "M Y", strtotime( $registered ) )
);
2
  • 4
    Little explanation would be great!
    – bravokeyl
    Commented Sep 19, 2016 at 7:11
  • 1
    wherever you want to print the date and time put this above code.. Commented Sep 20, 2016 at 11:18
2

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;

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