-- Collection of code snippets by Arne Vajhøj 
-- posted to eksperten.dk, usenet and other places (2002-now) 
CREATE ASSEMBLY udf FROM 'C:\udf.dll' WITH PERMISSION_SET = SAFE
GO

CREATE FUNCTION DATETIMEFORMAT(@dt DATETIME, @fmt NVARCHAR(50))
RETURNS NVARCHAR(50)
AS
EXTERNAL NAME udf.[E.DateTimeUtil].DateTimeFormat
GO

SELECT DBO.DATETIMEFORMAT(GETDATE(), 'MM/dd/yy HH:mm')
GO
SELECT DBO.DATETIMEFORMAT(GETDATE(), 'dd-MMM-yyyy HH:mm')
GO
SELECT DBO.DATETIMEFORMAT(GETDATE(), 'MM/dd/yyyy HH:mm:ss zzz')
GO

DROP FUNCTION DATETIMEFORMAT
GO

DROP ASSEMBLY udf
GO
