Transact-SQL RFC822 Date / Time Function for Stored proc RSS Generation

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())

returns:

Thu, 12 May 2005 21:29:29 GMT

Comments

  1. Anonymous1:38 AM

    Here is a much shorter version.

    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

    Cheers,
    --
    -oj

    ReplyDelete

Post a Comment

Popular posts from this blog

FIREFOX / IE Word-Wrap, Word-Break, TABLES FIX

Some observations on Script Callbacks, "AJAX", "ATLAS" "AHAB" and where it's all going.

IE7 - Vista: "Internet Explorer has stopped Working"