blakes01 Posted March 30, 2010 Share Posted March 30, 2010 Hi, I am wanting to create a simple RSS feed for the latest announcements on a clients website. The announcements are stored in a mySQL database. The rss feed itself actually works: http://www.castlefordaircadets.co.uk/announcement/rss/index.php However I have a field within my table called 'timestamp' which I cannot work out how to convert into a normal time that looks something similar to 'Monday 8th March 2010, 08:15'. Instead it just shows either "00:00" or "01:00". Below is the code on the RSS.class.php page <? class RSS { public function RSS() { require_once ('mysql_connect.php'); } public function GetFeed() { return $this->getDetails() . $this->getItems(); } private function dbConnect() { DEFINE ('LINK', mysql_connect (DB_HOST, DB_USER, DB_PASSWORD)); } private function getDetails() { $detailsTable = "entries"; $this->dbConnect($detailsTable); $query = "SELECT * FROM ". $detailsTable; $result = mysql_db_query (DB_NAME, $query, LINK); while($row = mysql_fetch_array($result)) { $details = '<?xml version="1.0" encoding="ISO-8859-1" ?> <rss version="2.0"> <channel> <title>Latest Announcements</title> <link>http://www.castlefordaircadets.co.uk</link> <description>2388 (Castleford) Squadron Latest Annoucements</description>'; } return $details; } private function getItems() { $itemsTable = "entries"; $this->dbConnect($itemsTable); $query = "SELECT * FROM ". $itemsTable; $result = mysql_db_query (DB_NAME, $query, LINK); $items = ''; while($row = mysql_fetch_array($result)) { $items .= '<item> <title>'. $row["title"] .'</title> <pubDate>'. $row["timestamp"] .'</pubDate> </item>'; } $items .= '</channel> </rss>'; return $items; } } ?> Anybody know how to convert my timestamp into a normal time/date. Thanks Link to comment https://forums.phpfreaks.com/topic/196994-rss-feed-timestamp/ Share on other sites More sharing options...
premiso Posted March 30, 2010 Share Posted March 30, 2010 Yep, Either pull it out of MySQL using it's built in DATE_FORMAT function or use PHP's date function. Personally, I would pull it out using MySQL's DATE_FORMAT. $query = "SELECT title, DATE_FORMAT(`timestamp`, '%Y-%d-%m %h:%i:%s') as timestamp FROM ". $itemsTable; Should get you what you want. Link to comment https://forums.phpfreaks.com/topic/196994-rss-feed-timestamp/#findComment-1034171 Share on other sites More sharing options...
blakes01 Posted March 30, 2010 Author Share Posted March 30, 2010 Thanks for your reply... Im a little rusty with php to be quite honest... Where do I put that piece of code? Link to comment https://forums.phpfreaks.com/topic/196994-rss-feed-timestamp/#findComment-1034178 Share on other sites More sharing options...
premiso Posted March 30, 2010 Share Posted March 30, 2010 Really? private function getItems() { $itemsTable = "entries"; $this->dbConnect($itemsTable); $query = "SELECT title, DATE_FORMAT(`timestamp`, '%Y-%d-%m %h:%i:%s') as timestamp FROM ". $itemsTable; Not really anything to do with PHP, more to do with sense. You replace the only query that uses $itemsTable with that one... Link to comment https://forums.phpfreaks.com/topic/196994-rss-feed-timestamp/#findComment-1034184 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.