meta
meta

Reputation: 167

Converting MySQL datetime to RSS pubDate using PHP?

i was wondering how would I convert datetime using PHP to work with RSS feeds pubDate?

Why is my browser 3 hours off when displaying the time? Is there a way to correct this?

Upvotes: 9

Views: 9820

Answers (5)

kander
kander

Reputation: 4286

<pubDate><? echo date("r", strtotime($data["added_on"])); ?></pubDate>

Courtesy of the first google result on 'mysql rss pubdate'

Edit: The off-time is probably due to timezone issues; it's not your browser, probably, it's the time being generated by PHP. Have you configured your PHP instance properly?

Edit: Sorry for the confusion guys, forgot to added the "Edit:" remark. No need to bash on the asker!

Upvotes: 5

btrandom
btrandom

Reputation: 118

<?php
$query = mysql_query("SELECT added_on FROM 'table');
while($row = mysql_fetch_array($query)){
?>
<pubDate><? echo date("r", strtotime($data["added_on"]));} ?></pubDate>

As BoltClock used the gmdate you WILL get the time in GMT, so you could calculate where you are easier. That said PHP is server side thus your browser might be +- 3 hours because the server is in a +-3 time zone from your browser. If you are experiencing that problem locally check for weird locales.

Upvotes: 4

Kibbee
Kibbee

Reputation: 66112

You can use the DateTime class as follows:

$objDate = new DateTime($itemDate);
$rssDate = $objDate->format(DateTime::RSS);

Where $row['date'] is the date from your row in MySQL. $rssDate with contain the properly formatted RSS Date.

Upvotes: 5

BoltClock
BoltClock

Reputation: 723388

Assuming $row is the resultant row of mysql_fetch_assoc() of your result, and your date column is called date:

<pubDate><?php echo gmdate(DATE_RSS, strtotime($row['date'])); ?></pubDate>

Upvotes: 11

Shubham
Shubham

Reputation: 22307

Use strtotime() to convert it into Unix timestamp then convert it into desired format using date()

Upvotes: 0

Related Questions