Forum Moderators: coopster

Message Too Old, No Replies

RSS PubDate from MySQL Date and Time Stamp

         

username

8:16 am on Sep 22, 2008 (gmt 0)

10+ Year Member Top Contributors Of The Month



Hi, I need to create a valid RSS PubDate. I am pulling values from a database and will be using EST as the timezone.

I have two values: $date and $time. These would be equivilant to:

$date = "2008-05-31";
$time = "20:39:00";

I have then been joining the two to equal:

$pubdate = "$date $time";

Which equals 2008-05-31 20:39:00.

How do I generate a complete RSS pubdate value from the above values?

Your thanks in advance.

dreamcatcher

3:03 pm on Sep 22, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you are pulling from the db, use DATE_FORMAT to reformat your date string:

DATE_FORMAT [dev.mysql.com]

Time should be ok as is, just append the time as you are doing.

dc

username

9:35 pm on Sep 22, 2008 (gmt 0)

10+ Year Member Top Contributors Of The Month



Thanks, but I am really looking for a solution which manages the values after they are pulled from the database. The main issue I am having, is obtaining the day equivilant. I can easily break apart a 2008-09-23 date into year, month, day, but need to get the following:

Tue, Sep 09 2008

I can seem to get out the day value.

Any ideas?

Thanks.

cameraman

9:49 pm on Sep 22, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



date [us3.php.net]('D, M d Y',strtotime [us3.php.net]($date));

username

1:18 am on Sep 23, 2008 (gmt 0)

10+ Year Member Top Contributors Of The Month



Thanks, I worked out this really great function, but there is one remaining issue:

$dateValue = "$date $time";//2008-09-23 06:50:31
$time=strtotime($dateValue);
$pubDate = date('D, d M Y H:i:s',$time);//Tue, 23 Sep 2008 06:50:31

Only issue is that RSS 2.0, to validate requires in my case EST on the end of the string. When I append this, the browser displays the time as if it were two hours earlier, i.e. 7 hours ago instead of 5 hours ago. Any ideas?

Thanks.

phranque

1:42 am on Sep 23, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



maybe you haven't correctly set the time zone [us.php.net]

username

2:26 am on Sep 23, 2008 (gmt 0)

10+ Year Member Top Contributors Of The Month



Hi Phranque, I am using:

putenv("TZ=Australia/Brisbane");

This works when not appending EST to the <pubDate> tag. i.e <pubDate>$pubDate EST</pubDate>

When I add the EST in, it throws it out by 2 hours. If I remove the Putenv line, the date stays the same, so am not sure that is affecting anything. I tried adding +0000 instead of EST, and that does some weird stuff with taking the time backward instead of maintaining it, which I thought it would, because the default is GMT. Any more ideas?

phranque

2:50 am on Sep 23, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



try using the date_default_timezone_set function instead and see if the problem goes away.
the solution may also depend on the PHP version you are using.
i would suggest reading all the contributed notes in the page i linked to in the previous post.

dreamcatcher

7:26 am on Sep 23, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks, but I am really looking for a solution which manages the values after they are pulled from the database. The main issue I am having, is obtaining the day equivilant.

Which can easily be accomplished using DATE_FORMAT. You should always let the database do the work where possible.

dc