An example:
<?php
$my_date = mysql2date("m.d.y", $info['post_date']);
echo 'date ' . $my_date;
?>
Function_Reference/mysql2date
Formatting_Date_and_Time
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 🙂
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
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.
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;
?>
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.