how to display datedate format like dd-MMM-YYYY

  • select datepart(dd,columnname) +'-'+datepart(mm,columnname) +'-'+datepart(yy,columnname)

    Check it out.

    karthik

  • rclgoriparthi (6/10/2008)

    it gives out put like this :- 27 Apr 08

    but i want out format like this 27-Apr - 2008

    Use function REPLACE on the result you've got.

    _____________
    Code for TallyGenerator

  • Once you have the month, you might need to use the Monthname function to get the full name. Look up date functions in Books Online.

  • looks like you result convert isnt big enough to start with char(6) wont hold dd_-_mmm_-_yyyy

    the format of type 6 give the two diget year you displayed and 106 gives the four digit year required

    as Sergiy suggested use the replace function is most probably the best optioni

    My suggested fragment would be

    replace(convert(char(15),fromdate,106),' ',' - ')

    what it does is get the date in format 106 = dd_mmm_yyyy (where _ is a space)

    replace then replaces spaces with a space + your hyphen + space

    Hope that is a solution for you.

  • yet another way 'to skin' the SQL cat:

    select replace(convert(char(11),getdate(),113),' ','-')

    😉

    RegardsRudy KomacsarSenior Database Administrator"Ave Caesar! - Morituri te salutamus."

Viewing 5 posts - 1 through 6 (of 6 total)

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