logo

Transact-SQL RFC822 DateTime UDF

Printer Friendly Version


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

My Biography
Pete is a consultant / architect and "UnEducator" using .NET. His samples at GotDotNet have been downloaded over 42,000 times. He enjoys jazz / classical music, digital photo artistry using Maya, fine wines and the beach. Pete is the co-founder / co-developer of eggheadcafe.com, and a Microsoft C# MVP and MCP. Read Peter's UnBlog at http://petesbloggerama.blogspot.com.