February 27, 2015 at 3:59 pm
Can any one share how to convert 6 digit number to mm/yyyy.
Thanks in Advance.
February 27, 2015 at 4:17 pm
Abhiram (2/27/2015)
Can any one share how to convert 6 digit number to mm/yyyy.Thanks in Advance.
What is contained in the 6 digit number?
--Jeff Moden
Change is inevitable... Change for the better is not.
February 27, 2015 at 4:44 pm
I have a column 062008 I want to display that number as 06/2008.
February 27, 2015 at 5:17 pm
Abhiram (2/27/2015)
I have a column 062008 I want to display that number as 06/2008.
SELECT STUFF(yourcolumn,3,0,'/')
--Jeff Moden
Change is inevitable... Change for the better is not.
February 27, 2015 at 11:51 pm
Further on Jeff's fine solution, you may want to consider converting the column from (var)character data type to date data type. Not only does it take less storage (3 bytes), it also enables you to do calculation on the column.
😎
Extending the previous method to return a date data type
SELECT CONVERT(DATE,'01/' + STUFF(yourcolumn,3,0,'/'),103)
Alternative method without any string manipulation
SELECT DATEADD(MONTH
,(((CONVERT(INT,yourcolumn,0) -1) % 10000) * 12)
+ (CONVERT(INT,yourcolumn,0) / 10000) -1
,CONVERT(DATE,'01/01/0001',103))
February 27, 2015 at 11:54 pm
Thank you very much. It worked.
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply