How to get 3 letter abbreviation for month in SQL

前端 未结 3 1014
眼角桃花
眼角桃花 2021-01-11 15:02

How to get month in 3 letters in SQL.

In SQL Table data is inserted:

2016-01-07 09:38:58.310

I need only month result in 3 letters

相关标签:
3条回答
  • 2021-01-11 15:10

    Try this (I am assuming you are using Sql Server).

    Select Convert(char(3), GetDate(), 0)
    

    If you need full name of month, try

    Select Datename(month, GetDate())
    
    0 讨论(0)
  • 2021-01-11 15:20

    Assuming you're using SQL Server 2012 or newer, you can use the FORMAT function:

    SELECT FORMAT([Date], 'MMM', 'en-US')
    

    Adapt the locale as needed.

    Since you're on SQL Server 2008, I'd use

    SELECT LEFT(DATENAME(MONTH, [Date]), 3)
    
    0 讨论(0)
  • 2021-01-11 15:29

    Or you could just do:

    LEFT(GETDATE(), 3)
    

    For instance you could declare a variable:

    Declare @MONTH VARCHAR(3)
    
    Set @MONTH = LEFT(GETDATE(), 3)
    
    0 讨论(0)
提交回复
热议问题