Convert Date format into DD/MMM/YYYY format in SQL Server

前端 未结 11 1381
臣服心动
臣服心动 2020-11-28 04:41

I have a query in SQL, I have to get a date in a format of dd/mm/yy

Example: 25/jun/2013.

How can I convert

相关标签:
11条回答
  • 2020-11-28 05:33

    Try this

    select convert(varchar,getdate(),100)
    

    third parameter is format, range is from 100 to 114, any one should work for you.

    If you need date in dd/mmm/yyyy use this:

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

    Replace getdate() with your column name. This worked for me.

    0 讨论(0)
  • 2020-11-28 05:34

    Simply get date and convert

    Declare @Date as Date =Getdate()
    
    Select Format(@Date,'dd/MM/yyyy') as [dd/MM/yyyy] // output: 22/10/2020
    Select Format(@Date,'dd-MM-yyyy') as [dd-MM-yyyy] // output: 22-10-2020
    
    //string date
    Select Format(cast('25/jun/2013' as date),'dd/MM/yyyy') as StringtoDate // output: 25/06/2013
    

    Source: SQL server date format and converting it (Various examples)

    0 讨论(0)
  • 2020-11-28 05:35

    Try using the below query.

    SELECT REPLACE(CONVERT(VARCHAR(11),GETDATE(),6), ' ','/');  
    

    Result: 20/Jun/13

    SELECT REPLACE(CONVERT(VARCHAR(11),GETDATE(),106), ' ','/');  
    

    Result: 20/Jun/2013

    0 讨论(0)
  • 2020-11-28 05:42

    we can convert date into many formats like

    SELECT convert(varchar, getdate(), 106)
    

    This returns dd mon yyyy

    More Here This may help you

    0 讨论(0)
  • 2020-11-28 05:43

    Anyone trying to manually enter the date to sql server 'date type' variable use this format while entering :

    'yyyy-mm-dd'

    0 讨论(0)
提交回复
热议问题