Time in activation_date

I would like how to set [[$listing.activation_date]] to:

  1. If less than 1 min than show how many mins from now;
  2. If less than 1 day then show how many hours from now;
  3. If more than 1 day than show how many days from now
{assign var="startDate" value = $smarty.now}
{assign var="endDate" value = $listing.activation_date|strtotime}
{math assign="diff" equation="(st - en)" st=$startDate en=$endDate }

 <div class="post-block-out featured">
	<div class="post-block feature-bg1">
	 {if $diff < 86400}<span class="new-ribbon-list"></span>{/if}
 </div> </div>

<div style="text-align:center;">[[$listing.activation_date]]</div>

How about something like this:

<?php
function ago($time)
{
   $periods = array("second", "minute", "hour", "day", "week", "month", "year", "decade");
   $lengths = array("60","60","24","7","4.35","12","10");

   $now = time();

       $difference     = $now - $time;
       $tense         = "ago";

   for($j = 0; $difference >= $lengths[$j] && $j < count($lengths)-1; $j++) {
       $difference /= $lengths[$j];
   }

   $difference = round($difference);

   if($difference != 1) {
       $periods[$j].= "s";
   }

   return "$difference $periods[$j] 'ago' ";
}

$var = ago(time() - 10);
echo $var;
?>

Personally, I would calculate the value before shooting it to your smarty template. Are you using a framework? If yes, you should have a controller and you should calculate it from there. You should always try to minimize the amount of code in templates :wink:

Note: I found the code here: http://css-tricks.com/snippets/php/time-ago-function/