Community & Support

x days, y hours and z minutes ago...

This appears to be one of those days when I'm completely blind when it comes to searching the API.

Drupal appears to have a library function that can convert a unix timestamp to this relative statement of "x days ago" or "has been a member for x weeks". I assume that this can be used by modules as well.

What's the name of this function?

Comments

Here's a snippet I copied

Here's a snippet I copied from somewhere that displays the 'time ago' in the 'What's new' block on the left of the www.batgung.com site, and hopefully will help you:

        echo( t('(%time ago)', array('%time' => format_interval(time() - $node->created,1))));

Thanks

That was exactly what I needed!

I especially like the part that the granularity can be adjusted through the second parameter. Now the only thing that could make it better would be to set a threshold unit (I'd rather have it as "30 days" instead of "4 weeks and 30 days")...

--
Arancaytar