database date output (2 posts)

  1. andrewtoohill
    Posted 3 years ago #

    I am running a query that is pulling from the database the post_title, the post_name, and the post_date. I am then outputting rows with this information. However the date is coming out like this: 2012-11-05 22:09:13 and I need it to come out like this: November 5, 2012 . Here is the code:

    $query_y = "SELECT post_title, post_name, post_date FROM $table_name WHERE post_type='post' AND year(post_date) = '$i' AND post_status = 'publish' ORDER BY post_date DESC";
             $myrows = $wpdb->get_results($query_y);
             echo "<ul class='custom'>";
             foreach($myrows as $myrow) {
    	         $title = $myrow->post_title;
    	         $permalink = $myrow->post_name;
    	         $date = $myrow->post_date;
    	         echo "<li>".$date."<br /><a href='".$permalink."' title='".$title."'>".$title."</a></li>";
  2. vtxyzzy
    Posted 3 years ago #

    WP stores its dates as a 'datetime' datatype - a string in the format you are getting. You need to convert this string to a 'timestamp' which can then be converted to your desired format.

    To use the default WP date format for your site, try this:

    $date = date_i18n(get_option('date_format'), strtotime($myrow->post_date));

Topic Closed

This topic has been closed to new replies.

About this Topic