SQL Date Format 107 Without Leading Zeros For The Day

时间:2016-04-04 18:39:07

标签: sql sql-server datetime

I am needing to convert a date/time stamp via SQL to the following format: April 4, 2016

Using

SELECT 
DATENAME(MM, GETDATE()) + 
RIGHT(CONVERT(VARCHAR(12), GETDATE(), 107), 9) AS [PaymentDate]

gets me almost what I need, however, it puts a leading 0 on the day, leaving me with: April 04, 2016

How can I get rid of that leading 0 on the day?

2 个答案:

答案 0 :(得分:2)

或者,如果您使用SQL Server 2012或更高版本,则可以使用FORMAT()功能:

Select Format(GetDate(), 'MMMM d, yyyy')
  

2016年4月4日

答案 1 :(得分:0)

this will work:

QUERY:

SELECT DATENAME(MM, GETDATE())+' '+DATENAME(dd, GETDATE())+' '+DATENAME(yy, GETDATE()) AS [PaymentDate];

RESULT:

enter image description here