Share » Forums » Developer » how long it is since a forum post was...

how long it is since a forum post was created

how long it is since a forum post was created

Tuesday 23 June 2009 3:29:00 am - 2 replies

Author Message

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

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu