Converting MySQL dateTime to RFC-822 (RSS pubDate) in PHP

I had the need to convert a MySQL datetime time stamp into a format accepted by the RSS 2.0 specification. To get the first part, you can do a SQL query like the following:

SELECT DATE_FORMAT(dateTimeColumn, '%a, %d %b %Y %T') AS rssPubDate FROM yourTable

After that, you need to get the timezone, which can be accomplished by using this:

$timeZone = date('T');

So lets say you store the rssPubDate from MySQL in a variable called $rssPubDate, all you need to do is $rssPubDate .= ” {$timeZone}”;

That’s it! You now have a RFC-822 compliant time stamp.

Author: Jack Slingerland

I'm a software engineer working and living in Raleigh, NC. I work in Python, Django, Node.js, React+Flux, AngularJS, and PHP. I like to work out with Kettlebells, run, and spend my free time with my wife, cat, and dog.

5 thoughts on “Converting MySQL dateTime to RFC-822 (RSS pubDate) in PHP”

  1. I want to ask how to store the rss pubdate in mysql , and which mysql datatype is used for storing pubdate in the DB.

Comments are closed.