scriptygoddess

15 Sep, 2002

Display specific words on days

Posted by: kristine In: Scripts

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.

8 Responses to "Display specific words on days"

1 | Michael Pate

September 15th, 2002 at 6:58 am

Avatar

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.

2 | Nate

September 15th, 2002 at 9:09 am

Avatar

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 :-)

3 | Jennifer

September 15th, 2002 at 3:27 pm

Avatar

neat little script! Great job! :)

4 | medic119

September 16th, 2002 at 11:07 am

Avatar

cool script.
Is there aneasy way to do this in Javascript as well??

5 | Shelagh

September 17th, 2002 at 11:32 am

Avatar

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!

6 | kristine

September 17th, 2002 at 11:47 am

Avatar

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!

7 | MT Plugin Directory

December 4th, 2002 at 10:40 pm

Avatar

Relative Date
Plugin version of my Scripts: Display specific words on days at ScriptyGoddess.

8 | kadyellebee

December 31st, 2002 at 7:19 pm

Avatar

slow day!
So since :gg: was wondering why I'd been quiet today, I realized I kinda was quiet!! I've been playing a

Featured Sponsors

Genesis Framework for WordPress

Advertise Here


  • Scott: Just moved changed the site URL as WP's installed in a subfolder. Cookie clearance worked for me. Thanks!
  • Stephen Lareau: Hi great blog thanks. Just thought I would add that it helps to put target = like this:1-800-555-1212 and
  • Cord Blomquist: Jennifer, you may want to check out tp2wp.com, a new service my company just launched that converts TypePad and Movable Type export files into WordPre

About


Advertisements