How to get an abbreviation of 3 letters per month in SQL

How to get a month of 3 letters in SQL.

The data is inserted into the SQL table:

2016-01-07 09:38:58.310 

I only need a month, the result: 3 letters, as shown below:

 Jan 
+5
source share
2 answers

Try it (I assume you are using Sql Server).

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

If you need the full name of the month, try

 Select Datename(month, GetDate()) 
+7
source

Assuming you are using SQL Server 2012 or later, you can use the FORMAT function:

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

Adapt the locale if necessary.

Since you are using SQL Server 2008, I would use

 SELECT LEFT(DATENAME(MONTH, [Date]), 3) 
+7
source

Source: https://habr.com/ru/post/1240079/


All Articles