2

This is Drupal 7: when I am logged in as administrator and I click "People" to check the registered users, the default Drupal display is the "Member for", which displays a time span. For example: "2 min 10 sec" or "23 hours 24 min" or even "6 days 22 hours". How can I change that display to a "Member since" display that would show the date and time the user actually registered? Thanks!

1 Answer 1

2

I'm not aware of an existing module that will do this but the following function in a custom module will do the trick:

function MYMODULE_form_user_admin_account_alter(&$form, &$form_state) {
  // Get the user IDs listed in the form
  $uids = array_keys($form['accounts']['#options']);

  // Since loading the user objects will incur overhead it would be best to get the
  // created data directly from the users table. It's a shame because this query has
  // already been run in user_admin_account(), but it's not saved anywhere that we can
  // easily pick it up.
  $sql = 'SELECT uid, created FROM {users} WHERE uid IN (:uids)';
  $created_data = db_query($sql, array(':uids' => $uids))->fetchAllKeyed();

  // Loop through the results and change the column data for the "Member for" column.
  foreach ($created_data as $uid => $created) {
    $form['accounts']['#options'][$uid]['member_for'] = date('d/m/Y H:i', $created);
  }

  // Finally change the header to say "Member Since"
  $form['accounts']['#header']['member_for']['data'] = t('Member Since');
}

The only thing you might want to change is the date format...see PHP's date() function for all the available tokens

2
  • Thanks! I will give it a try and update the status later on! Mar 22, 2012 at 17:56
  • Sorry it took me so long to test your code. I have tried it yesterday and it works 100% as expected! Thanks a lot! Apr 3, 2012 at 14:33

Your Answer

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

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