You must Sign In to post a response.
  • Category: SQL Server

    Please provide date format code in sql server

    Hi,
    I want to convert date into dd-MMM-yy, please provide solution.
    Convert(varchar(10),Date,'dd-MMM-yy')


    Thanks & Regards,

    Atul Sharma
  • #762221
    Hi

    You can try this Query form DD/MMM/yyyy format


    Select convert(varchar(12),GetDate(),101)
    Select convert(varchar(12),GetDate(),102)
    Select convert(varchar(12),GetDate(),103) -- DD/MM/YYY -> Format
    Select convert(varchar(12),GetDate(),106) -- DD/MM/YYY -> Format


    Name : Dotnet Developer-2015
    Email Id :kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • #762222
    Hi Atul sharma,

    There is no direct conversion for "dd-MMM-yy" format you need to write customized query for that.

    Refer below sample for the same,


    select convert(varchar(20),getdate(),106) -- 10 sep 2015
    select replace(convert(varchar,getdate(),106),' ','-') -- 10-sep-2015
    select substring(replace(convert(varchar,getdate(),106),' ','-'),1,7) -- 10-sep-
    select substring(replace(convert(varchar,getdate(),106),' ','-'),1,7)
    +substring(convert(varchar,datepart(yy,getdate())),3,4) -- 10-sep-15


    Hope this will helpful to you...

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #762974
    CONVERT(VARCHAR(10),GETDATE(),10)

    output will be:-
    11-04-2014

    hope this helps.

  • #763220
    Hi,

    select REPLACE(REPLACE(CONVERT(VARCHAR,getdate(),107), ' ','-'), ',','')

    Hope this will help

    Regards
    Sriram.r


Sign In to post your comments