July 30, 2010 at 9:36 am
This might be a stupid question, but in a select statement, how do I make
'2010-06-01 12:30:00'
display as (or something similar to)
'12:30PM on Tuesday June 1, 2010'
July 30, 2010 at 10:02 am
Some would say presentation is not the function of T-SQL but in the real world you could try something like this
SELECT CONVERT(VARCHAR(50),CURRENT_TIMESTAMP,113)
You could get closer to your requirement by concatenating various calls to DATEPART and DATENAME
July 30, 2010 at 11:49 am
this will give you exactly what you want
DECLARE @dt AS datetime, @strdt AS varchar(25)
SET @dt = getdate()
SET @strdt = convert(varchar, @dt,0)
SELECT ltrim(right(@strdt,Charindex( ' ',reverse(@strdt))) + ' on ' + datename(dw, @dt)+ space(1) + Convert(varchar, @dt, 107))
...you may use this a scalar function in your query
July 30, 2010 at 3:20 pm
What would be better is to do the formatting of data at the presentation layer. There are times (such as when producing system specific flat files) that this is not possible, but when it is it is generally a better idea than formatting the data with SQL Server.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply