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
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
Here is a much shorter version.
ReplyDeleteIF 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