Help - Search - Members - Calendar
Full Version: Making a post display time since it was posted
Movable Type Community Forum > Additional Resources > Tips and Tricks
notaw
I am wondering whether it is possible to configure MT to display not the date or the time of the post, but how long time has gone by since the post was posted?

In mins/hours/days etc -adjusting automatically etc.

Thanks in advance.

- N.
bmk
You could do this with some php in the MTEntries part of your template:
CODE
<?

$mtentrydate = "<MTEntryDate format="%m%d%Y%H%I%S">";
   $entrymonth = substr($mtentrydate, 0,2);
   $entryday =  substr($mtentrydate, 2,2);
   $entryyear =  substr($mtentrydate, 4,4);
   $entryhour =  substr($mtentrydate, 8,2);
   $entryminute =  substr($mtentrydate, 10,2);
   $entrysecond =  substr($mtentrydate, 12,2);

$entry_date = mktime($entryhour, $entryminute, $entrysecond, $entrymonth, $entryday, $entryyear);


$current_date = strtotime ("now");


$diff = $current_date - $entry_date;

$days = ($diff/86400);
$num_days = intval($days);

$hours = (($days - $num_days) * 24);
$num_hours = intval($hours);

$mins = (($hours - $num_hours) * 60);
$num_mins = intval($mins);

$secs = (($mins - $num_mins) * 60);
$num_secs = intval($secs);



echo "Posted $num_days days, $num_hours hours, $num_mins minutes, $num_secs seconds ago. <br />";

?>
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.