Reputation: 32861
I want to convert date format from 01/09 to January 2009 , 09/03 to September 2003 etc. Is this possible in SQL? Please let me know if there is a API for the same.
Upvotes: 1
Views: 343
Reputation: 3800
select datename(month, GETDATE()) + ' '+ substring(convert(varchar, GETDATE(), 100),8,4)
Upvotes: 0
Reputation: 26940
You should first convert it to a datetime. Then you can easily apply any formating when you read it later.
declare @d varchar(10);
set @d = '01/09'
select
--cast(@d as datetime) as d1, --syntax error converting char string
cast('20' + right(@d, 2) + '-' + left(@d, 2) + '-01' as datetime) as d2
then convert it to mmm yyyy using rm's answer
Upvotes: 0
Reputation: 26521
if you have a DateTime column in your table, it's possible
SELECT DATENAME(MM, YOUR_DATE_COLUMN) + ' ' + CAST(YEAR(YOUR_DATE_COLUMN) AS VARCHAR(4)) AS [Month YYYY]
http://www.sql-server-helper.com/tips/date-formats.aspx
Upvotes: 1