0

In Drupal 8, there is a "member for" in the profile page to show that how long time since this user be a member until now.

I would like to list all the user's "member for" via Views. However there is no such variable in the Views FIELDS.

I was thinking create a user field called "member since" and then every day get the "member for" value (which in the profile already) everyday, and display this "member since" field via Views. However:

  1. I don't know how to get the value of existed "member for" variable in Drupal 8 for created user field "member since". (of course I can calculate it by myself, but I don't want to deal the timestamp, formation etc)
  2. I don't know how to run this function to get the value of existed "member for" variable one time everyday.

Or is there a better way to do it (Note I need to use Views to display it)?

Thanks!

1 Answer 1

2

This is quite easy to achieve. Simply add the user's created field to your view, then change the field formatter for this to Time ago.

view field settings

2
  • Thanks a lot! but there is an "ago" after the time. Like "2 years 2 months ago" what I want is like "member for" "2 years 2 months". Is there any way to remove the "ago" there?
    – user71719
    Commented May 15, 2017 at 4:00
  • @DHH probably the easiest is to do this is to override the created field twig template for your view / display - then just use the twig replace filter (twig.sensiolabs.org/doc/2.x/filters/replace.html) to replace ' ago' with an empty string.
    – user34185
    Commented May 15, 2017 at 8:37

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.