tags:

views:

374

answers:

5

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?

+2  A: 
<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!

kander
Why is my browser 3 hours off when displaying the time?
meta
@meta Did you even read the answer before commenting? He told you: it's the time being generated by PHP, so check your timezone configuration in PHP.
Martin Bean
@Martin: did you even read and compare the timestamps of OP's comment and kander's edit?
BoltClock
Fair enough, egg truly worn on face!
Martin Bean
A: 

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

Shubham
+3  A: 

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>
BoltClock
A: 

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.

Kibbee
+1  A: 
<?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.

btrandom