Home » Php » php – What is the correct format for RSS feed pubdate?

php – What is the correct format for RSS feed pubdate?

Posted by: admin April 23, 2020 Leave a comment


I’m having trouble getting the date of my RSS Feed to run correctly. Do you know what the proper date to show it is?

I have it stored in a field called creation_date in this format: 2012-08-14 10:17:12

Then i grab it:

$pubDate = $article[creation_date];

Then I convert it:

$pubDate= date("Y-m-d", strtotime($pubDate));

Then within my item tag I place it:

<pubdate>'.date("l, F d, Y", strtotime($pubDate)).'</pubdate>

Is there something that I’m not seeing?

How to&Answers:

The PHP date function has already a way to format pubDate (RFC 2822) compliant dates:

date('r', $timestamp);



$pubDate = $article[creation_date]; 
$pubDate= date("D, d M Y H:i:s T", strtotime($pubDate));

then in my echo’d code:



See pubDate definition in RSS 2.0 Specification:

All date-times in RSS conform to the Date and Time Specification of RFC 822, with the exception that the year may be expressed with two characters or four characters (four preferred).

Here are examples of valid RFC822 date-times:

<pubDate>Wed, 02 Oct 2002 08:00:00 EST</pubDate>

<pubDate>Wed, 02 Oct 2002 13:00:00 GMT</pubDate>

<pubDate>Wed, 02 Oct 2002 15:00:00 +0200</pubDate>

See also Problematical RFC 822 date-time value.


Use this format: D, d M Y H:i:s O. See http://php.net/manual/en/class.datetime.php

Or use DateTime constants for more easy usage: DateTime::RSS


Rss pubDate uses the RFC 2822 standards. You can achieve this in php by invoking the r argument on the date function, i.e:

$pubDate= date('r', time());
echo "<pubDate>$pubDate</pubDate>";
# <pubDate>Thu, 20 Nov 2014 18:59:18 UTC</pubDate>

If you prefer the DateTime class, use:

$pubDate = new DateTime();
echo $pubDate->format(DateTime::RSS);


What about DateTime object (PHP 5 >= 5.2.0)

\DateTime::createFromFormat(\DateTime::RSS, $RSSDate); // converting RSS date to object


date(\DateTime::RSS, $timestamp); // formatting timestamp to RSS time

or both

$dto = \DateTime::createFromFormat(\DateTime::RSS, $RSSDate);
date('d-M-Y H:i:s', $dto->getTimestamp()); // formatting RSS date to anything you want

or even better

$dto = \DateTime::createFromFormat(\DateTime::RSS, $RSSDate);
$formattedDate = $dto->format('d-M-Y H:i:s');


While the accepted answer ("D, d M Y H:i:s T") works as expected most of the time, it is not 100% correct. In multilingual situations this string may give non English text which won’t be accepted as RFC compliant. To be always sure that the English version is used, use "r".


The easiest method is to use the DATE_RSS predefined constant (available since PHP 5.1.0).

$pubDate = date(DATE_RSS, strtotime($pubDate));


I have used like this:

$item->date = date('D, d M Y H:i:s GMT', strtotime($myBlogPublishedTime));

my hp rss sample