all groups > sql server programming > june 2003 >
You're in the

sql server programming

group:

Date/Time Format?


Re: Date/Time Format? Aaron Bertrand - MVP
6/30/2003 2:42:08 PM
sql server programming:
No, not directly, you'd have to write your own proc / function. You could
use this as a base:

http://www.aspfaq.com/2460


So it might be something like this:


CREATE FUNCTION dbo.formatWeirdDate
(
@dt DATETIME
)
RETURNS VARCHAR(32)
AS
BEGIN
DECLARE @r VARCHAR(32), @hr INT, @hrVC VARCHAR(4)
SET @hr = DATEPART(HOUR, @dt)
SET @hrVC = 'AM'
IF @hr > 12
BEGIN
SET @hr = @hr - 12
SET @hrVC = 'PM'
END
SET @hrVC = CAST(@hr AS VARCHAR(2)) + @hrVC

SET @r = DATENAME(DW, @dt) + ', ' + DATENAME(M, @dt)
+ ' ' + CAST(DAY(@dt) AS VARCHAR(2))
+ ', ' + CAST(YEAR(@dt) AS CHAR(4))
+ ' (' + @hrVC + ')'
RETURN @r
END
GO

SELECT dbo.formatWeirdDate(GETDATE())
GO

DROP FUNCTION dbo.formatWeirdDate
GO




Assuming SQL Server 2000, of course. It's always nice to know what version
you're using, so we're not chasing our tails for nothing...






[quoted text, click to view]

Date/Time Format? Jason Davis
6/30/2003 9:31:05 PM
Hi there,

I have a datetime field which needs to be displayed as:

"Monday, May 19, 2003 (10AM)"

How can I achive that?

Thanks

AddThis Social Bookmark Button