How to display the full month name from a date in SQL Server? I.e., the complete month names in all letters like January, February, March, April, May, etc. written out in full. This query shows you how to get the entire month names from the current date or any other date.
Indeed, with a simple SELECT GETDATE() you can display easily the current date. SQL Server provides really a lot of options to display the dates. It’s linked to the big variety of date format available in the countries around the world.
Display the full month name from a date in SQL Server
Indeed, various business needs are faced : display just a simple date, or a complete timestamp with milliseconds, for example to record sales transactions.
This SQL Server query displays the Month name using the DATENAME() SQL Server built-in function. It displays month in letters based on the month contained in a date or a timestamp. Indeed the tip is to use the DATENAME() function with the MONTH keyword. Combined with the GETDATE() time function to return the date of the day. In our example, we use the current date, but it works with “hard-coded” dates too.
T-SQL query to display the month name in all letters
The query below simply shows the month name using the MONTH option and the current timestamp with the default output format.
SELECT DATENAME(MONTH, GETDATE() ) AS [MonthName], GETDATE() AS [CurrentDate];
For example, it returns “June” in all letters for today.
T-SQL queries to display the year and day numbers
To go further, the query also works the same way for the day number and the year number.
SELECT DATENAME(YEAR, GETDATE() ) AS [Year], GETDATE() AS [CurrentDate]; SELECT DATENAME(DAY, GETDATE() ) AS [Day], GETDATE() AS [CurrentDate];
The result is 2018 for the first query.
The result is 11 for the second query.
Supposing that you are the 11th June 2018. Which is the date this article was first published.
To sum up, this short tutorial explains how to display the full month name in all letters from a SQL date.
Another post shows how to calculate a date difference with the hours, minutes and seconds.
By the way, we’d like to hear from you! Please do not hesitate to leave a comment or to contact us.