I wanted my RSS Blog feed to appear on http://www.sqlservercentral.com/ and one of the requirements was to include pubDate element following RFC 2822. Which is date time in the format below:
Mon, 02 Jul 2012 19:24:05 GMT
I generate my RSS feed using SQL Server stored procedure so I had to come up quickly with a way to format date. SQL Server does not provide a function (best to my knowledge) that would result in this format so I had to use multiple functions to get the same result.
Below is my T-SQL Code:
DECLARE @Date as datetime = '2012-07-02 19:24:05'
SELECT substring(datename(weekday,@Date),1,3) + ', '
+ RIGHT(DATENAME(DAY,@RSSDateTime),2) + ' '
+ SUBSTRING(DATENAME(MONTH,@Date),1,3) + ' '
+ DATENAME(YEAR,@Date) + ' '
+ CONVERT(nvarchar(8),@Date,108) + ' '
+ 'GMT'
The result of this function is:
Mon, 02 Jul 2012 19:24:05 GMT
Now that I have the correct format it is just a matter of modifying my stored procedure to generate pubdate RSS element in RFC 2822 format.
Take care
Emil