Jump to content

Recommended Posts

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

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

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.