Search code examples
sqlsql-serverdateselectmonthcalendar

How to return month short form from date in SQL Server?


I am using this code

SELECT DATENAME(month, GETDATE()) AS 'Month Name'

to get the month name. But how can I limit the name of the month up to 3 characters only? Example is FEB in this month.


Solution

  • Assuming you're using SQL Server, you can use the SUBSTRING function, i.e.

    SELECT SUBSTRING(DATENAME(month, GETDATE()), 1, 3) AS 'Month Name'