how to display datedate format like dd-MMM-YYYY

  • Hi,

    Good afternoon

    I want to display date date format like dd-MMM-YYYY

    eg:-

    My Requirement like this...

    from Date is 27th April 2008 then i want diplay this from Dat like this format 27-Apr-2008

    i tried like this

    SELECT CONVERT( CHAR(6), fromDate, 106 )

    FROM EMP

    it gives out put like this :- 27 Apr 08

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

    Plz hekp me to achive this

    Regds,

    Rclgoriparthi

  • 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 6 posts - 1 through 5 (of 5 total)

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