Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get 3 letter abbreviation for month in SQL

Tags:

sql-server

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 like below:

Jan
like image 321
mohd mazhar khan Avatar asked Jan 07 '16 10:01

mohd mazhar khan


People also ask

How do you abbreviate months name in SQL?

SQL SERVER: In SQL SERVER, we can use a combination of functions 'DATENAME' and 'DATEADD' functions to get a month name from a month number.

How do I display month in alphabet in SQL?

MySQL MONTHNAME() Function The MONTHNAME() function returns the name of the month for a given date.


2 Answers

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)
like image 137
marc_s Avatar answered Sep 21 '22 19:09

marc_s


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())
like image 27
Nitin Varpe Avatar answered Sep 21 '22 19:09

Nitin Varpe