How do I format the post date in Wordpress?

Mike picture Mike · Aug 11, 2013 · Viewed 47.8k times · Source

I have a sidebar where I want to show the most recent posts. Right now it shows the title, date, and an excerpt. The date shows the time which I want to get rid of. I show the date using this: $recent["post_date"]

 <?php
$args = array( 'numberposts' => '3' );
$recent_posts = wp_get_recent_posts( $args );
foreach( $recent_posts as $recent ){
    echo '<li id="sidebar_text"><b>'.$recent["post_title"].'</b></li><li style="font-size:12px">'.$recent["post_date"].'</li><li><i style="font-size:15px">'.$recent["post_excerpt"].'</i><a href="'.get_permalink($recent["ID"]).'"> Read   More</a></li>';
     }
 ?>

It shows the date like this: 2013-08-11 18:29:04 and I would like it like this 8-11-2013 and without the time. Thanks in advance.

Answer

ixchi picture ixchi · Aug 11, 2013
date('n-j-Y', strtotime($recent['post_date']));

This formats it the way you want. Just replace the $recent['post_date'] in your loop with that.