Title: Using post_date outside &quot;The Loop&quot;
Last modified: August 19, 2016

---

# Using post_date outside "The Loop"

 *  Resolved [ReallyConfused](https://wordpress.org/support/users/reallyconfused/)
 * (@reallyconfused)
 * [15 years, 5 months ago](https://wordpress.org/support/topic/using-post_date-outside-the-loop/)
 * Hi all,
 * I’m trying to use post_date outside “The Loop” as I want to display latest posts
   on my index page as well as in my blog section.
 * I’m using the following code:
 *     ```
       $data = mysql_query("SELECT * FROM wp_posts ORDER BY post_date DESC LIMIT 0, 5") or die(mysql_error()); while($info = mysql_fetch_array( $data ))
       {
       Print "<tr><td width=988><li><a href='website.com/news/?p=".$info['ID'] . "'>".$info['post_title'] . "</a> <font color=#666666><i> - posted on ".$info['post_date'] . "</td></tr>";
       }
       ```
   
 * However the problem is that it appears like so:
    - Post Title – posted on 2010-11-05 02:02:51
       rather than
    -  Post Title – posted on 05.11.10
       (the latter is how it appears in the actual
      blog index)
    - Can anybody help me out here?
    - Thanks in advance 🙂

Viewing 7 replies - 1 through 7 (of 7 total)

 *  [MichaelH](https://wordpress.org/support/users/michaelh/)
 * (@michaelh)
 * [15 years, 5 months ago](https://wordpress.org/support/topic/using-post_date-outside-the-loop/#post-1755624)
 * An example:
 *     ```
       <?php
       $my_date = mysql2date("m.d.y", $info['post_date']);
       echo 'date ' . $my_date;
       ?>
       ```
   
 * [Function_Reference/mysql2date](http://codex.wordpress.org/Function_Reference/mysql2date)
   
   [Formatting_Date_and_Time](http://codex.wordpress.org/Formatting_Date_and_Time)
 *  Thread Starter [ReallyConfused](https://wordpress.org/support/users/reallyconfused/)
 * (@reallyconfused)
 * [15 years, 5 months ago](https://wordpress.org/support/topic/using-post_date-outside-the-loop/#post-1755625)
 * Hi Michael, thanks for your speedy reply, I really appreciate it.
 * I’ve tried putting your example into my code, but it’s not working, I’m obviously
   missing something.
 * This is my original code:
 *     ```
       <?php
       mysql_connect("*******", "*******", "*******") or die(mysql_error());
       mysql_select_db("*******_*******") or die(mysql_error());
   
       $data = mysql_query("SELECT * FROM wp_posts ORDER BY post_date DESC LIMIT 0, 5") or die(mysql_error()); while($info = mysql_fetch_array( $data ))
       {
       Print "<tr><td width=5></td><td width=988><h3 class='left'><li><a href='website.com/news/?p=".$info['ID'] . "'>".$info['post_title'] . "</a> <font color=#666666><i> - posted on ".$info['post_date'] . "</td></tr>";
       } 
   
        ?>
       ```
   
 * Is there any chance you’d be kind enough to show me exactly how the code should
   look after your example has been implemented?
 * Thanks again 🙂
 *  [MichaelH](https://wordpress.org/support/users/michaelh/)
 * (@michaelh)
 * [15 years, 5 months ago](https://wordpress.org/support/topic/using-post_date-outside-the-loop/#post-1755629)
 * Assuming you are talking about this code being in one of your theme templates
   then
 *     ```
       posted on ".mysql2date("m.d.y", $info['post_date']);
       ```
   
 * If this is a site outside of WordPress, read Integrating_WordPress_with_Your_Website
 *  Thread Starter [ReallyConfused](https://wordpress.org/support/users/reallyconfused/)
 * (@reallyconfused)
 * [15 years, 5 months ago](https://wordpress.org/support/topic/using-post_date-outside-the-loop/#post-1755635)
 * Thanks for your reply again Michael.
 * > Assuming you are talking about this code being in one of your theme templates
 * No, I’m happy with my theme and my theme works great. But the theme index would
   be located at website.com/blog, as there is more to my site than just the blog.
   So on the index page of the site (which has no integration with WordPress or 
   my Theme) I would like to list my 5 most recent posts.
 * The code I posted above is the exact code from the section of the index page 
   and displays what I need, but is just let down by the formatting of the date.
 * I just need to alter the existing code, to format the date.
 * I read both of your suggested articles before making my original post and tried
   some of the suggested methods without success.
 *  [13Ham](https://wordpress.org/support/users/13ham/)
 * (@13ham)
 * [15 years, 5 months ago](https://wordpress.org/support/topic/using-post_date-outside-the-loop/#post-1755649)
 * mysql2date() wont’ work as it’s a wp function and you’re trying to run this outside
   of wp (which isn’t suggested).
 * a better plan would be to use your wp install as your entire cms, make a separate‘
   home’ page and declare that in settings as your home page and make a ‘blog’ page
   and put your blog inside of that. then you can use whatever wp functionality 
   you wish across the board. otherwise if you can’t be bothered,
 *     ```
       <?php
       $date = date('m.d.y', strtotime($info['post_date']));
       echo $date;
       ?>
       ```
   
 *  [MichaelH](https://wordpress.org/support/users/michaelh/)
 * (@michaelh)
 * [15 years, 5 months ago](https://wordpress.org/support/topic/using-post_date-outside-the-loop/#post-1755652)
 * Definitely read
 * [Integrating_WordPress_with_Your_Website](http://codex.wordpress.org/Integrating_WordPress_with_Your_Website)
 *  Thread Starter [ReallyConfused](https://wordpress.org/support/users/reallyconfused/)
 * (@reallyconfused)
 * [15 years, 5 months ago](https://wordpress.org/support/topic/using-post_date-outside-the-loop/#post-1755655)
 * Hi again, just to let you know I got this sorted using 13Ham’s code
 * `$date = date('m.d.y', strtotime($info['post_date']));`
 * Thank you very much 13Ham and MichaelH for all your help.

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Using post_date outside "The Loop"’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 7 replies
 * 3 participants
 * Last reply from: [ReallyConfused](https://wordpress.org/support/users/reallyconfused/)
 * Last activity: [15 years, 5 months ago](https://wordpress.org/support/topic/using-post_date-outside-the-loop/#post-1755655)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
