Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting MySQL datetime to RSS pubDate using PHP?

Tags:

php

mysql

rss

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?

like image 516
meta Avatar asked Jul 25 '10 16:07

meta


3 Answers

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>
like image 72
BoltClock Avatar answered Nov 01 '22 14:11

BoltClock


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.

like image 5
Kibbee Avatar answered Nov 01 '22 15:11

Kibbee


<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!

like image 5
kander Avatar answered Nov 01 '22 15:11

kander