views:

121

answers:

2

I'm modifying the Recent-Changes WordPress plugin to display dates. I can echo the date but can't format it; e.g., mm/dd/yyyy.

I'd like the post_modified date to be in mm/dd/yyyy.

I've tried--

echo '<li>'.$RecentChange->post_modified('m/d/Y').

-- but that caused the plugin to stop displaying posts, and generally broke the site.

Below is the relevant chunk from the plugin--

/* define full SQL request */
$rc_sql = "SELECT post_date, post_modified, post_title, ID FROM wp_posts WHERE ".$rc_content_sql." ORDER BY post_modified DESC LIMIT ".$rc_number;

global $wpdb;
echo $before_widget;
echo $before_title.$rc_title.$after_title.'<ul>';
$RecentChanges = $wpdb->get_results($rc_sql);

if ($RecentChanges)
foreach ($RecentChanges as $RecentChange) :
$rc_url = get_page_link($RecentChange->ID);
echo '<li>'.$RecentChange->post_modified.' <a href='.$rc_url.'>'.$RecentChange->post_title.'</a></li>';
endforeach;
echo '</ul>'.$after_widget;
$wpdb->flush(); 
}
+1  A: 

Assuming RecentChanges->post_modified is a PHP date or time, you could wrap it in PHP's date function and format it how you want.

date("m/d/Y", $RecentChanges->post_modified);

So, your line would look like this:

echo '<li>'.date("m/d/Y", $RecentChanges->post_modified).' <a  href='.$rc_url.'>'.$RecentChange->post_title.'</a></li>';

It's likely that your code is breaking WordPress because the post_modified function is just a getter and doesn't take parameters.

LunchboxG5
It does display a date, but the date is 12/31/1969. When I'm not formatting post_modified, I do get an accurate date. This is progress -- the site isn't broke.
smackaysmith
+3  A: 

Try

<?php
    mysql2date('m/d/Y', $RecentChange->post_modified);
?>

See reference.

UncleZeiv
No dates displayed when I attempted to use mysql2date.
smackaysmith
just to make sure, you added an "echo" in front of it, did you?
UncleZeiv
Yes, sir. echo '<li>'.mysql2date('m/d/Y', $RecentChanges->post_modified).' <a href='.$rc_url.'>'.$RecentChange->post_title.'</a></li>';
smackaysmith
I also switched to the default theme to make sure Thematic wasn't the problem.
smackaysmith
I had a typo -- $RecentChange, not $RecentChanges. Thanks for the help.
smackaysmith