Drupal Tip #1 – Formating Time Ago

Drupal has a nice little function called format_interval that formats a time interval in a “x secs ago” fashion. Note that it accepts a time interval, not an absolute time value, thus you need to subtract the time value from time().

For example, to print your node’s created time, use:

<?php echo 'Submitted ',format_interval(time()-$node->created),' ago'; ?>

Drupal API ref for format_interval()

Leave a Reply

Your email address will not be published. Required fields are marked *