Support our 100% FREE Projects: Donate Now OR Sponsor Now


  

RSS pubDate format in SQL Server

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

Share: Share on FacebookShare on Google PlusTweet it
Comments Add Comment
No data was returned. Share your thoughts, questions and suggest improvements:
Add Comment

You found us! Below are 50 most popular searched keywords

created at TagCrowd.com

Disclaimer: While every caution has been taken to provide our readers with most accurate information and honest analysis, please use your discretion before taking any decisions based on the information in this blog. Author will not compensate you in any way whatsoever if you ever happen to suffer a loss/inconvenience/damage because of/while making use of information in this blog.