Relative Dates
In a recent thread on the MT forums, a person asked how you could make the dates on entries relative to the current time. This means instead of "Posted on August 1st 2004" it would be "Posted 3 days ago." You could use the RelativeDate plugin but that would require you to rebuild your pages everyday (of course this can be done via a cron job).
Lucky I found this PHP script written by Kristine (kadyellebee on the forums). For this code to work, you will need to be using PHP enabled templates. Towards the top of your templates you should find a tag similar to
<$MTEntryDate$>
Just replace that with
<?php
//offset is how many hours away you are from your server.
$offset = "0";
$today = strtotime("now - $offset hours");
$mtdate = strtotime("<$MTEntryDate format="%Y%m%d %H:%M"$>");
if (date("Ymd", $mtdate)==date("Ymd", $today)) {
$hours = date("G", ($today - $mtdate));
$mins = date("i", ($today - $mtdate));
if ($hours<1) {$hourword="minutes";
if ($mins<10) { $mins=str_replace("0", "", $mins); }
$hours=$mins; }
elseif ($hours==1) { $hourword="hour"; }
else { $hourword="hours"; }
echo "Posted ", $hours, " ", $hourword, " ago";
}
else {
$days = date("j", ($today-$mtdate));
if ($days==1) { echo "Posted yesterday"; }
else { echo "Posted ", $days, " days ago"; }
}
?>
The only thing you need to specify is the offset time - in bold above. Whilst testing it out I noticed a little quirk though, the timezone I am in is ahead of my server's so when I put in a positive number the script calculated incorrectly, if I used the corresponding negative number it worked.
So if you're in a timezone ahead of your server you may need to put a - in front of the difference in hours !

Alex Grierson said:
on Apr 10, 2005 9:08 PM | Reply
The only tag I find is
<$MTEntrydate Format="%x"$>
Should I just replace this whole tag?
Arvind Satyanarayan said:
on Apr 10, 2005 9:12 PM | Reply
Yep replace the entire tag
Mayfield said:
on May 9, 2005 12:16 PM | Reply
When I add this PHP script to my main template it works for all posts except for the first. My first post will say something like, "Poster 31 days ago" then my second post will say, "Posted yesterday" and so on. What's the deal?
Richard said:
on Feb 5, 2007 10:08 PM | Reply
I have the same issue, 31 days ago on the first post.. I use it at the bottom of my post, as such (hopefully the code will show up properly here): by at
It looks like: Posted 31 Days ago by Richard at 10:48pm
soapbabes said:
on Mar 11, 2007 8:14 PM | Reply
Does anyone know a similiar script that would allow me to do the same thing, but rather than using hours and days, it will just use days and years. (ideally I would like days, months and years, but I appreciate that will be a lot harder to do months - what with the 28/30/31 day calculation)
I want to be able to calculate how old someone is from their date of birth vs. today's current date
I am using the Custom Category Fields MT plugin, and for each category (or in my case, each babe) I have given them a date of birth using the tag :
Is it possible to use this Relative Date snippet for days/years ?
example page (possibly nsfw): http://www.soapbabes.co.uk/coronation-street/tina-obrien/
Thanks in advance!