Transact-SQL RFC822 DateTime UDF

By Peter Bromberg

Have you ever wanted to generate RSS from a Stored procedure? It's easy, until you get to the RFC822 date requirement!

Have you ever wanted to generate RSS from a Stored procedure? It's easy, until you get to the RFC822 date requirement! Believe it or not, I could not find this anywhere-- I actually had to cobble it together from pieces myself. Enjoy:

5/17/05 NOTE: oj commented with a much better, shorter version which I've used to replace my original and is posted below:


IF OBJECT_ID('[dbo].[fnRFC822Date]', 'FN') IS NOT NULL DROP FUNCTION [dbo].[fnRFC822Date]
GO
CREATE FUNCTION [dbo].[fnRFC822Date]
(
@Date datetime
)
RETURNS nvarchar(70)
AS
BEGIN
RETURN(LEFT(DATENAME(dw, @Date),3) + ', ' + STUFF(CONVERT(nvarchar,@Date,113),21,4,' GMT'))
END
GO

-- example:
--print dbo.fnRFC822Date(getdate())

Note: thanks to oj, who posted this latest, shorter version as a comment on my UnBlog.


Submission Date:  9/23/2005 3:14:45 PM
Submitted By:  Peter Bromberg
My Home Page:  http://www.eggheadcafe.com

Popularity  (38 Views)