Convert SDT to date string

  • 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'

  • 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

  • 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

  • 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.

    └> bt



    Forum Etiquette: How to post data/code on a forum to get the best help[/url]

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply