November 24, 2011 at 3:20 am
I've a table created in a database in SQL Server 2005 .A field having datatype varchar(50) which contains date (ex. 20071015) in yyyymmdd format.I want month and year(Oct 2007).Please any body let me know how to do this ASAP.
Thanks VSP
November 24, 2011 at 3:36 am
Read about DATEPART. Or you can use the MONTH and YEAR functions. Try it out, and post again if there's anything in particular that you don't understand.
John
November 24, 2011 at 2:25 pm
SELECT STUFF(CONVERT(VARCHAR(11),CONVERT(datetime,'20071015',112),113),1,3,'')
As a side note: "ASAP" is not really among the preferred phrases on this site... It's usually combined with the word "money" 😉
Edit: two more issues:
1) it's highly recommended to store values in a format that represents the "true meaning". A date should be stored in a datetime column and not as varchar()
2) Formatting as you requested should be done at the presentation layer, if possible.
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply