1

Drupal 7 has ability to show since how long someone is member, like this:

Member for 2 months 21 hours

What date field it uses to save the registration date/time? How it calculates and displays this duration? And can't we use same module / method to calculate duration from our date (in node) and display in our views?

I am really in need of this functionality of calculating of duration, I am using views Calc and subtracting end-date from start-date and dividing it with number of seconds in day to get number of days between two days. but not satisfy besides don't know why can't subtract now() from a given date field in views calculations.

4
$account->content['summary']['member_for'] = array(
  '#type' => 'user_profile_item',
  '#title' => t('Member for'),
  '#markup' => format_interval(REQUEST_TIME - $account->created),
);

It's in function user_user_view($account). And yes, of course you can use format_interval($interval) function in other places.

  • I just discover it is very simple if one has to display the duration between a given date and today with "Time ago" Display of the date in views. it display member since xx year xx month etc. I would love to use it but have two problems, 1. cannot use filter on this i.e. member more than 4 years or member since 5 year etc. 2. I cannot do calculation on it i.e. 4 Years + duration2 = total duration. On other hand in views calc now() - date is not working and giving error that now value not allowed here. just looked at format_interval seems good but may not work with views calc. – user21354 Jan 8 '14 at 10:03
  • Thanks Molot and Gisle format_interval() work great. I am still struggling with calculated column for different duration and their total, but have learn so many things in last months. – user21354 Mar 12 '14 at 6:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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