scriptygoddess RSS Feed
 
 
 
 

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.

8 Responses to “Display specific words on days”

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

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

  3. 3
    medic119:

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

  4. 4
    Shelagh:

    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!

  5. 5
    kristine:

    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!

  6. 6
    Jennifer:

    neat little script! Great job! :)

  7. 7
    Michael Pate:

    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.

  8. 8
    Nate:

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

Categories

Archives

Bookmarks

WordPress Resources

Meta

ADVERTISEMENTS