How to display the full month name from a date with 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 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.
Indeed, various business needs are faced : display just a simple date, or a complete timestamp with milliseconds, for example to record sales transactions.
How to display the full month name from a date with 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. 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.
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” 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 [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.
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.