Date function

  • Dear all,

    In my database date is stored like '2004-01-07 00:00:00' & is it

    possible to print that date like Wednesday, January 07, 2004

    Can you plz help me on this

    Thanks,

    Chandru.

  • there is no one style that would do that, but you could use style 107 together with datename()

    select datename(dw,@date) + ', ' + convert(varchar, @date, 107)

    If you really need the month name to be full, then you would need to build up the string with multiple datename()

    Hope this offers some help....

    Kev

  • Ya that's correct have to use the multiple datename function

    for that requirement

    Thank's for helping me.

    Chandru.

  • Dear all,

    I have got the solution for my problem but is it anyother way to optimize

    this solution

    select datename(dw,'2004-01-07 00:00:00') + ' , '

    + datename(mm,'2004-01-07 00:00:00') + +' '+

    datename(day,'2004-01-07 00:00:00') +' , '+

    datename(year,'2004-01-07 00:00:00')

    Thank's

    Chandru

  • Ddin't

    select datename(dw,@date) + ', ' + convert(varchar, @date, 107)

    work for you?


    N 56°04'39.16"
    E 12°55'05.25"

  • not if Chandru needs the month name to be the full name - that's the issue with the solution I posted.

    Kev

  • Hi peso ,

    Actually my requirement is like i wanna to produce the o/p like

    Monday , August 11, 2008 but if i try with the Query that you have posted i'll get the o/p like Monday, Aug 11, 2008

    i have got the solution for that

    My Query

    SELECT DATENAME(dw,getdate()) + ' , ' +

    DATENAME(MM, getdate()) +

    RIGHT(CONVERT(VARCHAR(12), getdate(), 107), 9)

    AS [Month DD, YYYY]

    Thanks

    Chandru

  • Thanks kevriley & peso for helping me...

    Chandru

  • Oh... I see now.

    You want to have an extra space after weekday name.

    And you should be using Style 109 instead of 9 only, if you want century along with date.


    N 56°04'39.16"
    E 12°55'05.25"

Viewing 9 posts - 1 through 8 (of 8 total)

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