Smarty - elapsed time since posted for an entry?

Random stuff about serendipity. Discussion, Questions, Paraphernalia.
Post Reply
Don Chambers
Regular
Posts: 3657
Joined: Mon Feb 13, 2006 2:40 am
Location: Chicago, IL, USA
Contact:

Smarty - elapsed time since posted for an entry?

Post 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?
=Don=
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

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

Post 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
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
judebert
Regular
Posts: 2478
Joined: Sat Oct 15, 2005 6:57 am
Location: Orlando, FL
Contact:

Post 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.
Judebert
---
Website | Wishlist | PayPal
tpost
Regular
Posts: 77
Joined: Fri Sep 21, 2007 1:45 am

Post 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!
Don Chambers
Regular
Posts: 3657
Joined: Mon Feb 13, 2006 2:40 am
Location: Chicago, IL, USA
Contact:

Post 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?
=Don=
Post Reply