Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Format dates in a WordPress plugin

Tags:

wordpress

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(); 
}
like image 381
smackaysmith Avatar asked Aug 25 '26 07:08

smackaysmith


1 Answers

Try

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

See reference.

like image 191
UncleZeiv Avatar answered Aug 28 '26 15:08

UncleZeiv



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!