Advertisement
Advertisement


How to change mm/dd/yyyy to desired format


Question

I have date in format mm/dd/yy.For eg:4/1/2009 means April 1 2009.I want to get format as April 1,2009 in sql.Can anybody help?

2009/05/14
1
1
5/14/2009 9:32:07 PM


This should do what you want.

DECLARE @date datetime
SET @date = getdate()
SELECT datename(day,@date) + ' ' + left(datename(month,@date),3) + ' ' + datename(year,@date)
2009/04/21

declare @d datetime
select @d = '20090401'

select convert(varchar(50),@d,107)

will give you this

Apr 01, 2009

If you want 1 instead of 01 do this

declare @d datetime
select @d = '20090401'

select replace(convert(varchar(50),@d,107),' 0',' ')

Apr 1, 2009

2009/04/21

Source: https://stackoverflow.com/questions/771121
Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Email: [email protected]