How to display full month name from a date in SQL Server? Which is to say with the complete month names like January, February, March, April, May, etc. written out in full. This query shows you how to get the full 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 a lot, 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.
However, to display just a simple date, or a complete timestamp, for example to record sales transactions.
How to display full month name from a date in SQL Server?
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 and 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.
The query below is using the MONTH options provided by the DATENAME() SQL Server built-in function.
SELECT DATENAME(MONTH, GETDATE() ) AS [MonthName], GETDATE() AS [CurrentDate]
For example, it returns “June” for today.
To go further, the query also works the same way for the day number and the year number.
SELECT DATENAME(YEAR, GETDATE() ) AS [MonthName], GETDATE() AS [CurrentDate]; SELECT DATENAME(DAY, GETDATE() ) AS [MonthName], 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. This is how to display the full month name from an SQL Server date.
Another post shows how to calculate a date difference with the hours, minutes and seconds.
Don’t hesitate to get in touch to share your comments and appreciations on the blog.
By the way, I’d like to hear from you! Please do not hesitate to leave a comment or to contact me.