Page 1 of 1

Smarty - elapsed time since posted for an entry?

Posted: Fri May 23, 2008 12:32 am
by Don Chambers
Is it possible to know the difference between an entry's timestamp and the current time?

I'm working on a template that I would like to show the number of hours (and/or minutes) elapsed since the timestamp if the elapsed time is under a predetermined value (ie, perhaps less than 24 hours old)... and if greater than that value, show the timestamp as usual.

Ideas?

Re: Smarty - elapsed time since posted for an entry?

Posted: Fri May 23, 2008 10:43 am
by garvinhicking
Hi!

Yes, $smarty.now contains the current timestamp. Using {math} you can evaluate the difference between that and your entry's timestamp.

Regards,
Garvin

Posted: Fri May 23, 2008 3:18 pm
by judebert
It looks like you want human-readable date/time stamps. (Now I feel like that retarded paper clip!) Smarty doesn't actually include that function, but people have written modifiers to do the job.

Here's a Smarty forum post with two friendly time stamps.

This can go in your template's config.inc.php, as you already know.

Posted: Sat May 24, 2008 12:32 am
by tpost
We use the second Smarty modifier that judebert linked to in his post on our homepage.

Although we did make one customization to allow for weeks to be shown as well!

Posted: Sat May 24, 2008 12:46 am
by Don Chambers
I thought that tip had weeks.... anyway - care to share the config.inc.php code as well as how you use it in the tpl?