问题
How do I use sql to get the whole month name in sql server?
I did't find a way using DATEPART(mm, mydate)
or CONVERT(VARCHAR(12), CreatedFor, 107)
.
Basically I need in the format: April 1 2009.
回答1:
SELECT DATENAME(MONTH, GETDATE())
+ RIGHT(CONVERT(VARCHAR(12), GETDATE(), 107), 9) AS [Month DD, YYYY]
OR Date without Comma Between date and year, you can use the following
SELECT DATENAME(MONTH, GETDATE()) + ' ' + CAST(DAY(GETDATE()) AS VARCHAR(2))
+ ' ' + CAST(YEAR(GETDATE()) AS VARCHAR(4)) AS [Month DD YYYY]
回答2:
If you are using SQL Server 2012 or later, you can use:
SELECT FORMAT(MyDate, 'MMMM dd yyyy')
You can view the documentation for more information on the format.
回答3:
109 - mon dd yyyy (In SQL conversion)
The required format is April 1 2009
so
SELECT DATENAME(MONTH, GETDATE()) + RIGHT(CONVERT(VARCHAR(12), GETDATE(), 109), 9)
Result is:
回答4:
select datename(DAY,GETDATE()) +'-'+ datename(MONTH,GETDATE()) +'- '+
datename(YEAR,GETDATE()) as 'yourcolumnname'
来源:https://stackoverflow.com/questions/19619072/sql-server-get-the-full-month-name-from-a-date