SQL Server Forums
Profile | Register | 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
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

wsilage
Yak Posting Veteran

USA
74 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

3715 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
74 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

3715 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
52325 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  
 New 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.06 seconds. Powered By: Snitz Forums 2000