Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Converting a Date

Author  Topic 

wsilage
Yak Posting Veteran

82 Posts

Posted - 2013-04-19 : 11:04:10
I have a date time field that I need to convert, but not sure if it can be done this way or not.

I have 2012-12-21, but I need it to say December 2012. Can this be done and how?

Thanks in advance!

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-04-19 : 11:12:39
Usually it is better to do that type of formatting where the data is consumed (such as reporting services) rather than in the SQL Server database.
datename(month,YourDateColumn) + '  ' + cast(year(YourDateColumn) as char(4))
Go to Top of Page

wsilage
Yak Posting Veteran

82 Posts

Posted - 2013-04-19 : 11:28:01
Thanks, I didn't think of doing it that way.
Go to Top of Page

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-04-19 : 12:18:14
You are quite welcome - glad to help.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-04-20 : 06:32:39
if SQL 2012 you can use FORMAT also


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -