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:

1
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:

1
$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

Founder of Kernl.us. Working and living in Raleigh, NC. I manage a team of software engineers and wrk in Python, Django, TypeScript, Node.js, React+Redux, Angular, and PHP. I enjoy hanging out with my wife and son, lifting weights, and advancing Kernl.us in my free time.

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.