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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Converting a Date
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

wsilage
Yak Posting Veteran

USA
82 Posts

Posted - 04/19/2013 :  11:04:10  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

3873 Posts

Posted - 04/19/2013 :  11:12:39  Show Profile  Reply with Quote
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

USA
82 Posts

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

James K
Flowing Fount of Yak Knowledge

3873 Posts

Posted - 04/19/2013 :  12:18:14  Show Profile  Reply with Quote
You are quite welcome - glad to help.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52326 Posts

Posted - 04/20/2013 :  06:32:39  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000