Forums / Developer / how long it is since a forum post was created

how long it is since a forum post was created

Author Message

Angeliki Shearstone

Tuesday 23 June 2009 3:29:00 am

Hi,

We are looking do the following

Display how long it is since a forum post was created in the format days , hours , minutes

E.g. Posted 1 Day 5 Hours 10 Minutes

However we are finding it quite limiting trying to do this using the template language and wonder if any one knows how to do this or has a function or extension we can use that does this

Thanks in Advance

Jon Staines

Tuesday 23 June 2009 6:21:29 am

There are probably much neater solutions but if need be you can do something like:

{def $date_difference = sub( currentdate(), $node.object.published )
     $days = floor( div( $date_difference, 86400 ) )
     $hours_mins = mod( $date_difference, 86400 )
     $hours = floor( div( $hours_mins, 3600 ) )
     $mins = floor( div( mod( $hours_mins, 3600 ), 60) ) }

And display it with:

{$days} Days, {$hours} hours {$mins} minutes ago.

Of course, caching would cause the time to remain frozen. Plus you might want to add some logic to change Days to Day if there is only 1 etc.

Angeliki Shearstone

Tuesday 23 June 2009 7:35:59 am

Thank you!!!! You have actually written the code for me! It works perfect.

Thanks again.

Angelika