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

Arancaytar - January 15, 2007 - 07:43

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?

Here's a snippet I copied

mrb - January 15, 2007 - 08:52

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

Arancaytar - January 15, 2007 - 16:59

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

 
 

Drupal is a registered trademark of Dries Buytaert.