Display specific words on days
On request of someone in the MT forums, I put together a small php script that displays a different word (i.e. Today) depending on the date stamp of your server. This could be easily modified for any blogging software – this is pointed towards MT.
Here's the basics: If the day is today, display Today. If the day is 1 day ago, display Yesterday. Otherwise, show the Day of the Week.
<?
$today = date("m.d.Y");
$yesterday = date("m.d.Y", strtotime("-1 day"));
$mtdate = "<$MTEntryDate format="%m.%d.%Y"$>";
if ($mtdate==$today) {
echo "Today";
}
elseif ($mtdate==$yesterday) {
echo "Yesterday";
}
else {
echo("<$MTEntryDate format="%A"$>");
}
?>
Enjoy! Its working on my journal right now.
December 31st, 2002 at 7:19 pm
So since :gg: was wondering why I'd been quiet today, I realized I kinda was quiet!! I've been playing a
December 4th, 2002 at 10:40 pm
Plugin version of my Scripts: Display specific words on days at ScriptyGoddess.
September 16th, 2002 at 11:07 am
cool script.
Is there aneasy way to do this in Javascript as well??
September 17th, 2002 at 11:32 am
Does this work if your server is in a different time zone? My blog is set to +0 as I'm in the UK, but the server my site is on is in the US running om Singapore time!
September 17th, 2002 at 11:47 am
I actually made a change once I found out what timezone my server was in – its located on the east coast and I'm on the west coast, so I had to subtract 3 hours to make it absolutely correct
Here's how mine looks now – you should be able to adjust it similarly
<?
$today = date("m.d.Y", strtotime("-3 hours"));
$yesterday = date("m.d.Y", strtotime("-1 day – 3 hours"));
$mtdate = "<$MTEntryDate format="%m.%d.%Y"$>";
if ($mtdate==$today) {
echo "Today";
}
elseif ($mtdate==$yesterday) {
echo "Yesterday";
}
else {
echo("<$MTEntryDate format="%A"$>");
}
?>
Hope that helps!
September 15th, 2002 at 3:27 pm
neat little script! Great job!
September 15th, 2002 at 6:58 am
The funny things is, I went by your site last night and was wondering how that very function worked. I wake up this morning and find the answer.
September 15th, 2002 at 9:09 am
That's a handy script! Perhaps some variations of this would be useful as well, such as tying in the date with a javascript funtion which indicates how many hours ago (if today) else how many days ago. Not that I know how to do that
Thanks for posting this