Reputation: 33
Wondering if anyone could help with a problem I am getting in SQL Server.
Below is what I am trying to change date from 2016-09-01
to September 01
etc.
I am getting an error message when trying to convert the date.
set @start_date = '2016-09-01'
set @end_date = '2016-11-21'
SELECT pol AS [Policy],
DATENAME(MONTH, pol_dt) + ' ' + CAST(DATEPART(DAY, pol_dt)AS VARCHAR(2)) AS [Policy Date]
from pol_t
where pol_dt>= @start_date
and pol_dt<= @end_date
Upvotes: 3
Views: 82
Reputation:
Month DD 1
SELECT DATENAME(MM, GETDATE()) + ' ' + CAST(DAY(GETDATE()) AS VARCHAR(2)) AS [Month DD]
January 2
This is a great link for all things related to SQL Server and Date formatting.
http://www.sql-server-helper.com/tips/date-formats.aspx
Upvotes: 0
Reputation: 81960
IF 2012+ You could use format
Declare @D Date='2016-09-01'
Select Format(@D,'MMMM dd')
Returns
September 01
Format() has some great functionality, but it is not known for its performance
Upvotes: 1
Reputation: 309
try this ...
SELECT DATENAME(MONTH, SYSDATETIME())+ ' ' + RIGHT('0' + DATENAME(DAY, SYSDATETIME()), 2) AS [Month DD];
Upvotes: 0